By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Code Smell 12 – Null is Schizophrenic and Does Not Exist in The Real-world | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Code Smell 12 – Null is Schizophrenic and Does Not Exist in The Real-world | HackerNoon
Computing

Code Smell 12 – Null is Schizophrenic and Does Not Exist in The Real-world | HackerNoon

News Room
Last updated: 2026/01/05 at 9:01 PM
News Room Published 5 January 2026
Share
Code Smell 12 – Null is Schizophrenic and Does Not Exist in The Real-world | HackerNoon
SHARE

Programmers use Null as different flags. It can hint at an absence, an undefined value, en error etc. Multiple semantics lead to coupling and defects.

TL;DR: Null is schizophrenic and does not exist in real-world. Its creator regretted and programmers around the world suffer from it. Don’t be a part of it.

Problems 😔

  • Coupling between callers and senders.
  • If/Switch/Case Polluting.
  • Null is not polymorphic with real objects. Hence, Null Pointer Exception
  • Null does not exist on real-world. Thus, it violates Bijection Principle

Solutions 😃

  1. Avoid Null.
  2. Use the NullObject pattern to avoid ifs.
  3. Use Optionals.

https://hackernoon.com/null-the-billion-dollar-mistake-8t5z32d6?embedable=true

Refactorings ⚙️

https://hackernoon.com/code-refactoring-tips-no-015-remove-null?embedable=true

https://hackernoon.com/refactoring-029-how-to-replace-null-with-collection?embedable=true

https://hackernoon.com/refactoring-014-how-to-remove-if?embedable=true

Context 💬

When you use null, you encode multiple meanings into a single value.

Sometimes you want to represent an absence.

Sometimes you mean you have not loaded your objects yet.

Sometimes you mean error.

Callers must guess your intent and add conditionals to protect themselves.

You spread knowledge about internal states across your codebase.

Sample Code 📖

Wrong 🚫

class CartItem {
    constructor(price) {
        this.price = price;
    }
}

class DiscountCoupon {
    constructor(rate) {
        this.rate = rate;
    }
}

class Cart {
    constructor(selecteditems, discountCoupon) {
        this.items = selecteditems;
        this.discountCoupon = discountCoupon;
    }

    subtotal() {
        return this.items.reduce((previous, current) => 
            previous + current.price, 0);
    }

    total() {
        if (this.discountCoupon == null)
            return this.subtotal();
        else
            return this.subtotal() * (1 - this.discountCoupon.rate);
    }
}

cart = new Cart([
    new CartItem(1),
    new CartItem(2),
    new CartItem(7)
    ], new DiscountCoupon(0.15)]);
// 10 - 1.5 = 8.5

cart = new Cart([
    new CartItem(1),
    new CartItem(2),
    new CartItem(7)
    ], null);
// 10 - null  = 10

Right 👉

class CartItem {
    constructor(price) {
        this.price = price;
    }
}

class DiscountCoupon {
    constructor(rate) {
        this.rate = rate;
    }

    discount(subtotal) {
        return subtotal * (1 - this.rate);
    }
}

class NullCoupon {
    discount(subtotal) {
        return subtotal;
    }
}

class Cart {
    constructor(selecteditems, discountCoupon) {
        this.items = selecteditems;
        this.discountCoupon = discountCoupon;
    }

    subtotal() {
        return this.items.reduce(
            (previous, current) => previous + current.price, 0);
    }

    total() {
        return this.discountCoupon.discount(this.subtotal());
    }
}

cart = new Cart([
    new CartItem(1),
    new CartItem(2),
    new CartItem(7)
    ], new DiscountCoupon(0.15));
// 10 - 1.5 = 8.5

cart = new Cart([
    new CartItem(1),
    new CartItem(2),
    new CartItem(7)
    ], new NullCoupon());
// 10 - nullObject = 10

Detection 🔍

Most Linters can flag null usages and warn you.

Exceptions 🛑

You sometimes need to deal with null when you integrate with databases, legacy APIs, or external protocols.

You must contain null at the boundaries and convert it immediately into meaningful objects.

Tags 🏷️

  • Null

Level 🔋

[x] Intermediate

Why the Bijection Is Important 🗺️

When you use null, you break the bijection between your code and the MAPPER.

Nothing in the mapper behaves like null.

Absence, emptiness, and failure mean different things.

When you collapse them into null, you force your program to guess reality and you invite defects.

AI Generation 🤖

AI generators often introduce this smell.

They default to null when they lack context or want to keep examples short and also because it is widespread (but harmful) industry default.

AI Detection 🧲

You can instruct AI to remove nulls with simple rules.

When you ask for explicit domain objects and forbid nullable returns, generators usually fix the smell correctly.

Try Them! 🛠

Remember: AI Assistants make lots of mistakes

Suggested Prompt: Rewrite this code to remove all null returns. Model absence explicitly using domain objects or collections. Do not add conditionals

Without Proper Instructions 📵

  • ChatGPT
  • Claude
  • Perplexity
  • Copilot
  • You
  • Gemini
  • DeepSeek
  • Meta AI
  • Grok
  • Qwen

With Specific Instructions 👩‍🏫

  • ChatGPT
  • Claude
  • Perplexity
  • Copilot
  • You
  • Gemini
  • DeepSeek
  • Meta AI
  • Grok
  • Qwen

Conclusion 🏁

  • Null is the billion-dollar mistake. Yet, most program languages support them and libraries suggest its usage.

Relations 👩‍❤️‍💋‍👨

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xviii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xix

https://hackernoon.com/how-to-get-rid-of-annoying-ifs-forever-zuh3zlo

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-viii-8mn3352

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxx

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xliii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxix

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxvi

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xlii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xx-we-have-reached-100

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-ix-7rr33ol

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-v-evj3zs9

More Information 📕

https://hackernoon.com/null-the-billion-dollar-mistake-8t5z32d6?embedable=true

Credits 🙏

Photo by Kurt Cotoaga on Unsplash


I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

Tony Hoare

https://hackernoon.com/400-thought-provoking-software-engineering-quotes?embedable=true


This article is part of the CodeSmell Series.

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-i-xqz3evd?embedable=true

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Garmin Users No Longer Need a Separate App to Track Their Calories and Macros Garmin Users No Longer Need a Separate App to Track Their Calories and Macros
Next Article Sony and Honda’s Afeela EV will start customer deliveries in late 2026 Sony and Honda’s Afeela EV will start customer deliveries in late 2026
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Fairphone surprises Gen 6 owners with early Android 16 rollout
Fairphone surprises Gen 6 owners with early Android 16 rollout
News
What you need to know about SASSA grants payments
What you need to know about SASSA grants payments
Computing
QCon London 2026: SBOMs Move From Best Practice to Legal Obligation as CRA Enforcement Looms
QCon London 2026: SBOMs Move From Best Practice to Legal Obligation as CRA Enforcement Looms
News
Forget next day, Amazon is introducing much faster deliveries
Forget next day, Amazon is introducing much faster deliveries
Gadget

You Might also Like

What you need to know about SASSA grants payments
Computing

What you need to know about SASSA grants payments

11 Min Read
Understanding OpenAI’s Sora and GPT-5.2 – Chat GPT AI Hub
Computing

Understanding OpenAI’s Sora and GPT-5.2 – Chat GPT AI Hub

9 Min Read
Can You Trust What AI Tells You About SEO? We Tested It! | WordStream
Computing

Can You Trust What AI Tells You About SEO? We Tested It! | WordStream

32 Min Read
RemotiveLabs and Vayavya Labs move ADAS validation into the full vehicle E/E architecture | HackerNoon
Computing

RemotiveLabs and Vayavya Labs move ADAS validation into the full vehicle E/E architecture | HackerNoon

6 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?