3 ms·
Null references are not a mistake, they make perfect sense. Letting nullable types be dereferenced directly is the mistake. Null references are at the core of
by microcolonel 7y ago
Null references are not a mistake, they make perfect sense. Letting nullable types be dereferenced directly is the mistake.
Null references are at the core of a great number of sensible datastructures, and they're a natural fit for conventional computers.
- int_19h 7y agoThere are two separate concepts here that often gets conflated. There's null reference in a sense of a special pointer value (usually all bits set to 0) that means "this doesn't point to anything". That's a useful low-level tool that allows for compact representation of many important data structure. And then there's null reference in a sense of type systems. To be more specific, "null reference" here is really a shortening of "every reference in the type system is implicitly nullable". And that is the billion dollar mistake. An explicitly nullable reference type that requires explicit check on dereference, or option types, that use null pointers under the hood, are obviously not the problem.
- dooglius 7y ago> "null reference" here is really a shortening of "every reference in the type system is implicitly nullable" I don't think this is quite accurate, there are definitely cases where non-null pointers are required (e.g. dereferencing). It's more correct to say that the type system does not explicitly indicate whether a pointer might be null or not.
- microcolonel 7y agoJust consider all pointers null until proven otherwise, shouldn't be that hard to do something like this in static analysis. Even if a reference is non-null, you still have to wonder if it's valid.
- throwaway2048 7y agoTo put it a bit more compactly, why is Boolean logic "True, False, Null"