4 ms·
When one writes code which is close to the processor, for instance, one has a reason to write in C, one can represent an unallocated memory structure with a nul
by jpz 8y ago
When one writes code which is close to the processor, for instance, one has a reason to write in C, one can represent an unallocated memory structure with a null pointer, or one can use a boolean value.
A null value means something in that context. I don't see how it means nothing.
If I have a tail-recursive function, I probably do not need null. But if I have a loop which may run 0 or more times, and need to catch the absence of runs, I need to model a None result.
In that instance, the null has semantic meaning. I can use an algebraic type of course, but for the task I am doing, that may not be practical.
Saying that null logically doesn't exist is not true if my context is the Linux kernel. The unqualified statement of such seems to be overly categorical, to me.
I do like your analogy with NoSQL, I think it's an excellent point. Nullability in a JSON document for instance is better modelled with absence - however, with a language which is compile-time type-checked, those absent values may need to be present in materialised classes as nullable values (options if you like) - unless you're dictionaries all the way down like Python.