The ridiculous cargo cult hate that null has developed in recent years is one of my pet peeves, but I'll try to avoid a full blown rant and stick to one incorrect premise of this article: "Null does not exist [in the] real world."
Null absolutely exists in the real world. You know what I'm holding in my hand right now? Nothing, ie null. I'm not holding an object that represents nothing, I'm holding nothing, no thing, not anything. There is no better code representation of that state than null. What smells is this modern demand that we all pretend an object can represent no object.
You know what doesn't exist in real life? Anything resembling a NullCoupon. Besides that, you are now instancing yet one more object that has to be tracked and garbage collected, all because of some irrational dislike of null. So in addition to being a less accurate representation of the real world, this pattern is also less efficient.
Tony Hoare is wrong, he did not make a mistake by including null, because null is a valid state, both in programming and the real world, and coders making mistakes like not checking for null isn't a problem with null any more than not checking for 0 before division is a problem with 0 itself.
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
I will stick to this Besides that, you are now instancing yet one more object that has to be tracked and garbage collected. and the answer is 'who cares about GCs?' We are talking about good models, no premature optimization leading to early and tight coupling.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The ridiculous cargo cult hate that null has developed in recent years is one of my pet peeves, but I'll try to avoid a full blown rant and stick to one incorrect premise of this article: "Null does not exist [in the] real world."
Null absolutely exists in the real world. You know what I'm holding in my hand right now? Nothing, ie null. I'm not holding an object that represents nothing, I'm holding nothing, no thing, not anything. There is no better code representation of that state than
null
. What smells is this modern demand that we all pretend an object can represent no object.You know what doesn't exist in real life? Anything resembling a
NullCoupon
. Besides that, you are now instancing yet one more object that has to be tracked and garbage collected, all because of some irrational dislike ofnull
. So in addition to being a less accurate representation of the real world, this pattern is also less efficient.Tony Hoare is wrong, he did not make a mistake by including null, because null is a valid state, both in programming and the real world, and coders making mistakes like not checking for
null
isn't a problem withnull
any more than not checking for0
before division is a problem with0
itself.Different things with different behaviors.
I keep thinking Tony Hoare is right :)
I will stick to this Besides that, you are now instancing yet one more object that has to be tracked and garbage collected. and the answer is 'who cares about GCs?' We are talking about good models, no premature optimization leading to early and tight coupling.