3 ms·
Why is this? Sometimes, you do want to indicate that nothing came back. Python has the concept of None, which seems to function this way. You must check if th
by blackrock 6y ago
Why is this? Sometimes, you do want to indicate that nothing came back.
Python has the concept of None, which seems to function this way. You must check if the return type is None, and react appropriately.
- hn_throwaway_99 6y agoNull is not a problem with programming languages that correctly support (and enforce) optionals. The problem with null in, say, Java is that any object reference can potentially be null, which makes it very difficult to know when and why you should verify that something is non-null.
- blackrock 6y agoThis is the key. Didn’t Go or Rust figure this out correctly?
- hn_throwaway_99 6y agoLots of languages have since figured it out. Kotlin (which runs on the JVM) handles it well, https://kotlinlang.org/docs/reference/null-safety.html https://kotlinlang.org/docs/reference/null-safety.html, as does Swift.
- ufo 6y agoIt's a more obvious problem in typed languages like C or Java, where the type system can't help much to protect you against null pointer exceptions if you forget to check for null. Specially in C, where the null pointer exceptions cause billions of dollars of damage in the form of segfaults and nasal demons. In a language like Python the possibility that variables may contain values of different type (such as the None value) is part of the game. An inherent tradeoff of being dynamically typed.
- hydroxideOH- 6y agoIn Racket and Scheme, false is the only 'falsy' value, with everything else evaluating 'truthy', which is nice since you don't have to worry about the specifics of the return type. I think the bigger issue with null or None, though, is not necessarily using it as a return type (where that makes sense, and can be enforced by a type system) but when objects are mutated to the value of null. The bigger issue there is with mutation and side-effects, but having null there as a convenient short cut can be a foot gun that leads to lots of errors.