4 ms·
I don't think null is necessarily bad. Sometimes, you either have a type or nothing at all. It's when nullable is the default that undoes us, I think. It should
by deathanatos 11y ago
I don't think null is necessarily bad. Sometimes, you either have a type or nothing at all. It's when nullable is the default that undoes us, I think. It should be an explicit choice that your type is <thing|null>, not an implicit one. That's the problem with Java references, or C pointers: it's on by default and you can't opt-out; since null is always a valid value for those types, I can't inform the type checker that null isn't a valid input (or a possible output) from a function, so if someone mistakenly passes one, you won't find out until runtime.
Contrast to Rust's Option<Foo> type; you know when null (None in Rust) is a possibility, because it's in the type. (And in Rust, you're forced to deal with it, too.)
- paulddraper 11y agoYou are right that null can be problem when encoded wrong in a statically typed language. But they cause problems even without static types. https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ https://www.lucidchart.com/techblog/2015/08/31/the-worst-mis... For example, Rust can have Option<Option<T>>, which can be None, Some(None), or Some(Some(...)). But you can represent that with null, because nulls don't "stack".