• Artwork@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    23 days ago

    This is quite interesting, since the article states absolutely nothing about Go language.
    Since, it’s the most common or even fairly standard technique in the language:

    func Hello(name string) (string, error) {
        // If no name was given, return an error with a message.
        if name == "" {
            return "", errors.New("empty name")
        }
        // ...
    }
    

    Source: go.dev/doc/tutorial/handle-errors

    • lbfgs@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      22 days ago

      Go’s val, err := maybeDoThing() pattern isn’t the same thing because it’s not a discriminated union like Rust’s Result or C++'s std::expected or the Typescript example in the article. Moreover, due to restrictions in Go’s generics, it’s impossible to implement what is imo the most attractive pattern enabled by the discriminated union Result types - monadic operations.

    • felsiq@piefed.zip
      link
      fedilink
      English
      arrow-up
      3
      ·
      23 days ago

      Ditto for rust, although I didn’t read the article to know if they mentioned that one lol