← Back to context

Comment by rowanG077

1 day ago

Unwrap is an explicit action. Checking an error is usually just forgotten. No unwrap can enter your code without the dev being accutely aware of it.

Your Go code won't compile if you don't check the error, though.

  • Did you ever use go?

    ``` package main

    import ( "errors" "fmt" )

    func getMessage() (string, error) { return "DO NOT INSPECT", errors.New("something went wrong") }

    func main() { msg, _ := getMessage() // Ignore the error. fmt.Println(msg) } ```

    Compiles normally and prints "DO NOT INSPECT"

    • > Did you ever use go?

      Don't make me spit my tea. That monitor is expensive. Of course, yes: https://git.sr.ht/~bayindirh/nudge

      Jokes aside...

      You used "_" to ignore the error variable, which I call "IDGAF" placeholder.

      So, you willingly ignored the error and tell me that you don't have to check the error? You told the compiler that you don't care about the error explicitly (via "_"). That's on you then.

      In my first comment I noted in the P.S. section:

          ...if you ignore the error, this is a deliberate choice and the burden is on the developer.
      

      You used "_" knowingly. Compiler/linter didn't add it there by itself.

      I mean, do you even read the language documents to understand how a language works?

      1 reply →