20 ms·
I don't understand the ritual flagellation of nulls that seems to be in vogue recently. The null value is a necessary and critically important value: sometimes
by hehetrthrthrjn 6y ago
I don't understand the ritual flagellation of nulls that seems to be in vogue recently.
The null value is a necessary and critically important value: sometimes you have to represent 'nothing.' It's not particularly special as a value. It doesn't break type systems that are designed for it.
The issue seems to be that some people forget that their code might receive null values and that nulls are represented as a zero pointer which cause an exception if dereferenced.
The resulting backlash is worse than the disease: straightjacketing languages and littering them with more busywork.
I've gone the opposite direction in my work: not only can pointers be null but so can all other basic types. It's incredibly useful and a real design win.
- TotempaaltJ 6y agoI think the reason is the discrepancy between what you're saying (which is true) and reality: > sometimes you have to represent 'nothing.' Languages in which all values can /also/ be null break the "sometimes" requirement there. Not all variables/parameters should be able to represent nothing. Representing nothing isn't the issue here, I doubt anyone disagrees that that's useful (there are still Options). The fact that anything can be nothing is.
- hehetrthrthrjn 6y agoI get that, but the solution is not "enforce it with static type checking", especially when the default is non-nullable. In my experience nullability is a dynamic constraint and it's most often just passed through various functions, until it becomes an issue some function. Static null checking then just becomes madness. Other representable values can also can be invalid inputs to some code, but we don't implement draconian constraints throughout the code to manage that.