2 ms·
How do zero values help here? Zero values would seem to me to make nil pointer panics easier to run across, because it means the language can silently insert ni
by pcwalton 11y ago
How do zero values help here? Zero values would seem to me to make nil pointer panics easier to run across, because it means the language can silently insert nil into your data structures or assign nil to your variables without any syntactic indication.
> The problem with having nil is when you expect a value to be either a valid pointer or nil to indicate an error, and you forget to check for an error.
That's not the problem with null pointers. Null is used all over the place for non-error conditions. The problem is when an object legitimately might or might not be present, but the type doesn't encode that fact, so some code mistakenly assumes that the object is always present when it isn't.
- masklinn 11y ago> The problem is when an object legitimately might or might not be present, but the type doesn't encode that fact, so some code mistakenly assumes that the object is always present when it isn't. Yes reworded slightly, types encode value invariants, nullable types can't encode one of their invariants.