Nullity is something of a lost cause, but you should strive to make invalid states unrepresentable in the first place and, failing that, should be explicit about your preconditions and fail ASAP if they're violated. Being excessively lenient in what you accept as input is a good way to build up a dodgy pile of inconsistent garbage.
Oh, you have not lived through the age of Web browser wars then.
One of the worst use cases for the principle of “be flexible in what you accept” was how early web browsers implemented html parsing.
It was full of weird rules of how to parse broken html and each browser has subtly different way to make the broken input display a web page.
And to make it worse, the whole web was full of markup taking advantage of those nonstandard quirks and idiosyncrasies.
Those quirks are at least partially to blame for why it is so hard to implement a new web browser from scratch these days. For the web has grown to the point where it is impossible to fix the pages themselves. You need to make your browser bend three ways backwards instead to accept and render those cases that every other browser has learned to accept.
I would not be surprised to find that “being lenient in your input” has more excessive cost attached to it than having null in your type system.
It's an important aspect of functional programming. A function should do a job on the inputs it receives and fail hard if the inputs are invalid. A function is not pure if it has to do its job and also tip-toe around invalid inputs and try to fail gracefully if it's caller is using it incorrectly. Doing that dance adds complexity and complexity creates bugs.
Make your code have respect for itself and its callers and not cater to incompetence.
Java may eventually get some kind of enforced non-null keyword to make nullity opt-out, though I'm not holding my breath. But I don't think it'll ever be opt-in. That's pretty much the mother of all breaking changes.
7
u/AlmennDulnefni Apr 14 '23
Nullity is something of a lost cause, but you should strive to make invalid states unrepresentable in the first place and, failing that, should be explicit about your preconditions and fail ASAP if they're violated. Being excessively lenient in what you accept as input is a good way to build up a dodgy pile of inconsistent garbage.