NULL is a convenient way to map singularities in your model of the problem. I have on a few occasions tried to write NULL-less code, and it adds a good bit of work. - model all possible states for a value - determine appropriate default actions for all types - meaningful place-holder values It's a good exercise, and I think more code should be written this way, but - as an Engineer I'm trying to model just enough of…
NULL: The worst mistake of computer science? (2015)
31–40 of 377 posts
Re: NULL: The worst mistake of computer science? (2015)
#32The problem is in tooling. If all compilers/builders out there could detech null for us, those kinds of error could be taken care with much more ease.
I can't speak for other IDEs, but Intellij will always warn me if I'm exposing myself to some NULL operations.
I do think better first class language support is the way to go though.
Re: NULL: The worst mistake of computer science? (2015)
#33Other candidates: - null terminated strings - machine dependent integer widths
> null terminated strings This is mentioned. > machine dependent integer widths What exactly do you dislike about this?
Or what do you even do about it?
A handful of solutions already exist: - Use a higher-level language - Java
Re: NULL: The worst mistake of computer science? (2015)
#34Re: NULL: The worst mistake of computer science? (2015)
#35At least C# has the syntactic sugar to easily check for null references which lets you avoid the horrors of code like `(if s != null && s.length)`. Instead you can type `s?.length`. Never have I appreciated syntactic sugar as much.
if (s) then do stuff with s;Re: NULL: The worst mistake of computer science? (2015)
#36Earlier quoted context omitted.
nullptr is actually "a prvalue of type std::nullptr_t" or something like that. Since C++11 NULL is the same as nullptr.
And it is directly convertible to a bool. The primary effectiveness seems to be with operator overloading where a NULL could trigger an integer method instead of a pointer method.
Re: NULL: The worst mistake of computer science? (2015)
#37Nulls in strongly typed languages can get rather weird but from a C/C++ perspective it is the same as 0. nullptr is just a correctly casted 0.
The two languages should not be conflated anymore.
Re: NULL: The worst mistake of computer science? (2015)
#38Nulls in strongly typed languages can get rather weird but from a C/C++ perspective it is the same as 0. nullptr is just a correctly casted 0.
nullptr is actually "a prvalue of type std::nullptr_t" or something like that. Since C++11 NULL is the same as nullptr.
Re: NULL: The worst mistake of computer science? (2015)
#39Isn't there an inherent need in programming to express an explicit "nothing" value? Coming from Python and JS, I never found None/null to be much of a problem. I in fact like the distinction of null and undefined in JS. Using null allows you to distinguish from the accidental undefined.
Re: NULL: The worst mistake of computer science? (2015)
#40Isn't there an inherent need in programming to express an explicit "nothing" value? Coming from Python and JS, I never found None/null to be much of a problem. I in fact like the distinction of null and undefined in JS. Using null allows you to distinguish from the accidental undefined.
There is a need for a nothing value in many cases and languages without an implicit null, such as Haskell, F# and Rust, employ an ‘option’ type. It’s a dedicated type that either contains a value or nothing. It forces you to declare when you expect a potential null and to check for it.