4 ms·
That’s true, but ostensibly you only use it in places where you expect nulls and don’t intend to debug anything. That’s why Smalltalk, C#, CoffeeScript, and pro
by bcherny 9y ago
That’s true, but ostensibly you only use it in places where you expect nulls and don’t intend to debug anything. That’s why Smalltalk, C#, CoffeeScript, and probably JS and TS soon have null chaining.
- _sdegutis 9y agoObjective-C also allows nil to receive messages which then just returns nil also. I’ve always found this really natural in that you can assume something is either valid or null and avoid a whole lot of null checks this way. That said, I’ve never been terribly frustrated by other languages either which throw when calling methods on null. Maybe it’s because of heavy use of certain design patterns that make it so it’s never really a surprise?
- sametmax 9y agoIt also means a chained call with an nil in it still complete from start to end. So it has additional overhead, and you better not have side effects in there. All in all, I'd like to have some kind of "?" operator in Python, I do think the pros are most of the time greater than the cons.