News for hackers. Stuff that matters.
Re:Why nullable types? by munificent on Tuesday December 08, 2020 @12:37PM (#25348602)
> Different people will assign different meanings to null, and it's a real headache when trying to write generic code.

This is a legitimate concern, but my experience has been that it is a surprisingly rare problem in practice. We software engineers are trained to believe that any system that supports 1 of something is obligated to generalize and support N of them. But you'd be surprised how far just one sentinel value gets you.

I mean, one of the key observations underpinning having nullable (and thus non-nullable) types is that most places in your code need zero of these sentinel values. Most type, around 90% the last time I tried to count, don't permit null at all, so needing two distinct absent values is quite rare.

Re:Why nullable types? by int_19h on Tuesday December 08, 2020 @06:05PM (#25352784)
The bigger problem in generic code is that flattening means that you can't distinguish between incoming nullable values (that you don't know are nullable, because it's a type parameter!) that are null, and nulls in your own code.
Re:Why nullable types? by creata on Tuesday December 08, 2020 @05:07PM (#25352038)
Yeah, it is a rare problem, but it's not that rare when writing anything generic. For example, look at all the special-casing of null (ctrl-f "null") in the Java HashMap docs.[0] All of that would immediately go away if they didn't have null.

[0]: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap....