• arc@lemm.ee
    link
    fedilink
    arrow-up
    2
    arrow-down
    2
    ·
    1 year ago

    Swift and Rust have a far more elegant solution. Swift has a pseudo throw / try-catch, while Rust has a Result<> and if you want to throw it up the chain you can use a ? notation instead of cluttering the code with error checking.

    • barsoap@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      The exception handling question mark, spelled ? and abbreviated and pronounced eh?, is a half-arsed copy of monadic error handling. Rust devs really wanted the syntax without introducing HKTs, and admittedly you can’t do foo()?.bar()?.baz()? in Haskell so it’s only theoretical purity which is half-arsed, not ergonomics.

      • arc@lemm.ee
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        1 year ago

        You can say it’s half-arsed if you like, but it’s still vastly more convenient to write than if err != nil all over the place