• baseless_discourse@mander.xyz
    link
    fedilink
    arrow-up
    0
    ·
    5 days ago

    The more I read about these kind of article the more I am amazed that our digital future is at hand in utterly incompetent people.

    This person clearly have no understanding of monadic error (AKA Maybe/option monad or slightly more advanced Either monad), which is the first monad we teach at a class targeting second year undergrad.

    The performance is just plain factual error. The functional error code will continue to compute n2 when computation of n1 failed; the same do not happen in the exception version. If you compare code with completely different trace, of course they will have different performance… A properly implemented monadic error will return as fast as compute for n1 failed, and never execute the rest. This is the default and idiomatic behavior for any properly implemented monad, like in haskell, ocaml, F#, and rust. This performance problem even shouldn’t happen in linq style handling like in C#, Kotlin (maybe Typescript?).

    The point of monadic error is that its control flow is local, whereas exception is non-local. Unless you have clear documentation about the possible error, then the return value is deceptive. And the error can be handled anywhere in the code base. And programmer knows non-local control flow (goto, break, contiune, exception, long jump) is the breeding ground for spaghetti code, so that many non-local control (goto, long jump) is baned in most languages.

    That being said, there are certainly cases, with proper documentation, the exception style is easy to write and understand. But I think they are specific scenarios that have to be justified on a case-by-case basis.

    • noddy@beehaw.org
      link
      fedilink
      arrow-up
      0
      ·
      4 days ago

      I think the author of the article just haven’t understood how to use the ? operator yet, and don’t think they deserve being called “utterly incompetent” for it. Whether something is a monad or not is not necessarily something a programmer should have to think about on a daily basis IMO.

      I just think of rust errors as a tagged enum with either a value or an error. And the ? operator as syntax sugar for returning if something was an error. IMO that simple understanding is sufficient to do error handling in Rust. I don’t think we should gatekeep programming behind some intellectual barrier of whether or not you understand category theory. I certainly don’t understand what a monad is, but I can still write working software and do error handling without unwraps.

    • ulterno@lemmy.kde.social
      link
      fedilink
      English
      arrow-up
      0
      ·
      4 days ago

      I was making a shared library at work and was recently asked to start throwing exceptions, because the users wouldn’t care to check my returned error and just continue with the empty returned data.
      Well, now they will most probably have an empty catch block and continue doing what they did before.

      Nothing can fix a lazy worker.

      Anti Commercial-AI license