3 ms·
Yep I get that point. However, how would you avoid extra allocations and maintain safety (no nulls)?
by azth 13y ago
Yep I get that point. However, how would you avoid extra allocations and maintain safety (no nulls)?
- kasey_junk 13y agoI actually have no problem with the extra allocations if they maintain safety (that's not quite true, I actually need to break safety occasionally). The problem is that the incoherent design of the collections library means that it is not clear to the programmers of the default mutable hash map lookup what they are striving for. If they were striving for performance they would use a model that allowed for NPE against safety, that had allocation semantics that were sensible. Conversely, if safety was the overriding concern they wouldn't allow for the NPE. Instead, in one of the most central data structures of the language we get unreasonable behavior. This is clearly a sign of bad design, thus reputing the original assertion that the Scala collections library were a good example of type programming. PS: To trivially answer your question, they should have inverted the implementation here. A NPE throwing method for lookup wrapped with option sugar would make way more sense than the inverse.
- azth 13y agoMakes sense, thanks for your answer :)