
Boosted by isagalaev ("Ivan Sagalaev :flag_wbw:"):
tymwol@hachyderm.io ("Timothy Wolodzko") wrote:
The "do something and if it fails return None" pattern is responsible for a lot of strange bugs in Python code. Stop doing this! None is a valid return type only if "no result" is a valid result. Yeah, in languages like Rust or Haskell the Option monad is pretty popular, but they also force handling it properly. In dynamic languages, you end up with "None" strings, math errors when doing arithmetic operations on None, or even less pretty bugs. In such a case, None should be returned only in cases where user should expect it as a valid result, so is expected to handle it properly. Otherwise, it begs for bugs.