4 ms·
> Honestly I don't think including null in the language is a big deal. Academics tend to think it is a big deal because it makes it harder to prove programs cor
by lmm 12y ago
> Honestly I don't think including null in the language is a big deal. Academics tend to think it is a big deal because it makes it harder to prove programs correct, but almost nobody does that with Java programs, so it doesn't really matter to most programmers.
Speak for yourself. As a professional Java (well, mostly Scala) programmer, not a week goes by without a null pointer exception slowing down development.
> the language needs a way to represent the state that an object starts out with. For integers and floats that is 0, for booleans it is false, and for objects it is null.
No, you don't need a value, you just need semantics for what happens if you do that. E.g. you could make a UninitializedValueException that would only be thrown when you tried to access an uninitialized field. That would be effectively the same behaviour as currently in that case, but it would be much easier to diagnose than NullPointerException, since it can only be thrown when you access an uninitialized field, not e.g. because a map didn't contain a particular entry.
> Even assuming we could somehow solve the efficiency problems with a super-clever compiler and a built-in optional type
This is disingenuous. It's not "somehow" with a "super-clever" compiler. It's a triviality.
> C++ got a non-nullable type in the form of references, and it didn't exactly turn the language into a paragon of sweetness and light. It just made things more confusing and annoying since you had to keep flipping back and forth between pointers and refereences, depending on the API you were using.
That's an argument for not trying to retrofit non-null references onto an existing language. It's not an argument for having nullable references in a new language.
> And in typical C++ fashion, they invoked undefined behavior to answer the question of what happened if you accessed a not-yet-initialized reference (for example in a constructor).
Don't do that then.