Richard Bucker

Is null really a billion dollar mistake?

Posted at — Jan 4, 2013

I plan to read the article from the professed inventor or null; for the moment, however, I do not imagine that it’s a real mistake.  Back in the day when memory was not protected we would assign 0x00 (zero) to pointers to signify the absence of value or null. With high level and OO languages this concept needed to be more formal. Simply assigning 0x00 to the pointer was not going to be a good thing because that address could actually hold an object instance. There are any number of sentinel values that could be used in it’s place but the same thing would happen.  Alternatively, depending on the language creating an anonymous null object instance could accomplish the same thing but then it’s a full fledged object instance with plenty of other baggage.

The thing is… if you remove null from your programming style guide you’ll simply have to replace it with something else that is less rigorous or “invented here”.  And that’s just silly because null translates across many languages, platforms and frameworks where your version might not.

But good luck to you. I’m keeping it.

UPDATE:
I started to read your post and then decided to watch the video. Sadly I do not think that null is as bad as Hoare thinks. At first it was a tradeoff between checking and not checking. Checking was slow and not checking was fast… but by about minute 25 he finally explains that if you did not invent null that you’d have to do something else that implements null-like behavior. This sounds quirky to me. The null problem can be taken a step further when you apply some lessons from Erlang.  Simply let it fail. Specially if you know the data is supposed to be good.  For example when I get the IP address from a tool like ipconfig or ifconfig I assume (right or wrong, that the IP address is formated properly and valid for this context. So why would I implement a complex regex to validate all the possible IP addresses when a simple one would allow me to pull the IP address from the target document easily enough?  I wouldn’t and neither should you.

The other reason why removing null pointer references as in your examples… his argument was for language architects (internals). It was not for userspace applications.