Tony Hoare's Null References: The Billion Dollar Mistake
1–10 of 14 posts
Re: Tony Hoare's Null References: The Billion Dollar Mistake
#2Just because your programming language supports null pointers, doesn't mean you need to use them. You can avoid the pitfalls discussed by Tony Hoare by simply refraining to use them. You will still need to handle null pointers coming into your code from outside, like from libraries, but your own code does not need to generate them.
Re: Tony Hoare's Null References: The Billion Dollar Mistake
#3Re: Tony Hoare's Null References: The Billion Dollar Mistake
#4Re: Tony Hoare's Null References: The Billion Dollar Mistake
#5Not sure if it is possible to have "only valid object exists, ever" and have it working for real. In pointers we have NULL to signal "not a pointer". In floats we have NAN to signal "not a number". In integers I miss not-an-integer enough that I often designate INT_MIN as not-an-integer representation. I notice when working with indices, index 0 is a convenient not-an-index value. Don't know enough theory to figure i…
The next level is constructing types in a way that you can avoid such low level details of whether the pointer is valid.
In other words, encode the state in the type instead of a value that you need to test against every time you want to use it.
Re: Tony Hoare's Null References: The Billion Dollar Mistake
#6Re: Tony Hoare's Null References: The Billion Dollar Mistake
#7I particularly appreciate that as a billion-dollar mistake, Javascript decided to make it twice (null and undefined).
Re: Tony Hoare's Null References: The Billion Dollar Mistake
#8I particularly appreciate that as a billion-dollar mistake, Javascript decided to make it twice (null and undefined).
There's no standard, widely-accepted way to unambiguously serialize and deserialize nulls within querystrings. JavaScript is perhaps one of the more frequent client languages for that, but Python and many other server-side languages are affected too. Could we do something about that?
I liked the look of the proposal at https://github.com/whatwg/url/issues/469 that was working towards this.
In short, it provides the ability for "?a&b=" to represent the variable "a" containing null and "b" containing an empty-string.
Re: Tony Hoare's Null References: The Billion Dollar Mistake
#9Re: Tony Hoare's Null References: The Billion Dollar Mistake
#10Not sure if it is possible to have "only valid object exists, ever" and have it working for real. In pointers we have NULL to signal "not a pointer". In floats we have NAN to signal "not a number". In integers I miss not-an-integer enough that I often designate INT_MIN as not-an-integer representation. I notice when working with indices, index 0 is a convenient not-an-index value. Don't know enough theory to figure i…
The simple existence of "Not an object" value is fine. The abstraction built over the raw value should be good enough that it will confront you when you attempt to use it. The next level is constructing types in a way that you can avoid such low level details of whether the pointer is valid. In other words, encode the state in the type instead of a value that you need to test against every time you want to use it.
Consider a non-blocking read. What the caller does depends on whether the read returns a value or "no data available". If the type of the object returned depends on whether there was a value, you just replaced a null check with a type check.
You can avoid that check with a caller with multiple return points and have the callee pick between them. Exceptions are the most obvious way to do that. However, exceptions happen immediately, while type/null checks can be done later.