Python has the concept of None, which seems to function this way. You must check if the return type is None, and react appropriately.
Python has the concept of None, which seems to function this way. You must check if the return type is None, and react appropriately.
Didn’t Go or Rust figure this out correctly?
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.
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.