5 ms·
Respectfully I think you're not addressing the point I'm making, but a slightly different one. In the case where a piece of data can be missing, and that's fin
by davnicwil 7y ago
Respectfully I think you're not addressing the point I'm making, but a slightly different one.
In the case where a piece of data can be missing, and that's fine, I completely agree that optional/maybe types are useful to model that explicitly and unambiguously. They let you and future maintainters know that this is the case, via the type system, at compile time.
But what I'm talking about here is genuine runtime exceptions (which NPE is in Java, of course), where the design of the system says that this piece of data cannot be missing and yet, at runtime, you encounter a case where it is missing, erroneously, because of some bug somewhere.
Types like optionals won't help you here, because you wouldn't have used them at design time anyway. The same applies to languages completely without null references.
All type systems do is formalise expectations about how data is going to look. If the real data breaks from those expectations because of some bug at runtime, the type system can't help you.
- RHSeeger 7y ago> But what I'm talking about here is genuine runtime exceptions (which NPE is in Java, of course), where the design of the system says that this piece of data cannot be missing and yet, at runtime, you encounter a case where it is missing, erroneously, because of some bug somewhere. My experience is that this is the less common of the cases in a production environment (vs dev where one may be experimenting a bit more).
- davnicwil 7y agoI agree with you :-)
- deleted 7y ago[deleted]
- boomlinde 7y ago> But what I'm talking about here is genuine runtime exceptions (which NPE is in Java, of course), where the design of the system says that this piece of data cannot be missing and yet, at runtime, you encounter a case where it is missing, erroneously, because of some bug somewhere. With checked optionals, you'll know that the code differs from the design at compile time. If a piece of data can indeed be missing you can't compile the code without considering that case explicitly.