• TehPers@beehaw.org
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    Because the reality is that people don’t document errors (what exceptions can be raised by a method), don’t explicitly handle all the cases (how many times have you returned a 500 in a Flask app from missing an error type in your except block/missing an errorhandler), or don’t even think to put a try…except around fallible code (I see this a lot, anecdotally). The Either monad (or Rust’s Result, which I’m more familiar with) force you to do something with the error explicitly.

    Exceptional cases are just as normal a part of a program as any other flow, including the success flows. If you have 20 happy paths and 80 exception paths, and only cover those 20 happy paths, you’ve covered 20% of the cases.