• @[email protected]
    link
    fedilink
    2611 months ago

    Yes it is a hard error and Go does not compile then. You can do _ = foobar to fake variable usage. I think this is okay for testing purposes.

    • @MonkCanatella
      link
      2911 months ago

      I think that’s even worse because it increases the likelihood you’ll forget you faked that variable just for testing

      • @[email protected]
        link
        fedilink
        111 months ago

        Worse than not having a unused variable check at all? Dunno, the underscore assignment are very visible for me and stand out on every code read and review.

        • @[email protected]
          link
          fedilink
          11
          edit-2
          11 months ago

          Yes, worse, because now if you want to use the underscore assignment to indicate that you really want to discard that variable - it gets confused with underscore assignments that were put there “temporarily” for experimentation purpose.

          • @merc
            link
            911 months ago

            Exactly.

            Say I’m having some issue with a function. I comment out half the function to see if that’s where the weirdness is. Golang says “unused variable, I refuse to compile this dogshit!” I completely fool Golang by just using _ = foo. Yes, I was correct, that’s where the problem was. I rewrite that section of the code, and test it out, things work perfectly. Only now, it turns out I’m not using foo anymore, and Golang has no idea because I so cleverly fooled it with _ = foo.

            Now, something that could be caught by a linter and expressed as a warning is missed by the language police entirely, and may make it into production code.

            Police the code that people put into a repository / share with others. Don’t police the code that people just want to test on their own.

    • @[email protected]
      link
      fedilink
      811 months ago

      Ew, that’s awful. Go is not one of my programming languages but I had always held it in high esteem because Ken Thompson and Rob Pike were involved in it.

      • @merc
        link
        511 months ago

        That’s the main reason it has had any success. It’s not that it’s a good language, it’s just that it has good references.

      • @[email protected]
        link
        fedilink
        111 months ago

        Honestly, it does not happen often that I have a ln unused variable that I want to keep. In my mind it is the same thing when wanting to call a function that does not exists. Also my editor is highlighting error Long before I try to compile, so this is fine too for me.

    • @[email protected]
      link
      fedilink
      5
      edit-2
      11 months ago

      The underscore is used in production code too. It’s a legitimate way to tell the compiler to discard the object because you don’t intend to use the pointer/value.