anderseknert,
@anderseknert@hachyderm.io avatar

I'll just say it — the forced "unused variable" compiler check is one of my least favorite features of . That shit is for linters to deal with.

michenriksen,
@michenriksen@chaos.social avatar

@anderseknert I agree. It would be nice if it was a warning for go run and a build error for go build

anderseknert,
@anderseknert@hachyderm.io avatar

@michenriksen That's an interesting idea!

jasonsando,

@anderseknert IDE starts screaming at you while you're halfway with your changes, you'll be like dangit did I mess up that declaration I need it in 2 seconds ... nah it's whining because you're not using it yet 😒Not sure I'm ready to punt it to the linter, but I empathize.

shinyzenith,

@anderseknert I sort of get where you're coming from and at the same time it does prevent me from making some stupid bugs.

I like how :zig: + zls handles it.
If you define an unused variable and format the buffer using zls, it will discard it automatically using _ = variable. Then when you proceed to use it later on, zls will again catch onto the "pointless discard" and remove the above line :zig:.

If you choose not to format with zls, ofc it will emit the error as usual!

anderseknert,
@anderseknert@hachyderm.io avatar

@shinyzenith If they'd take that stance consistently, I'd sort of understand it. But you can do all sorts of obvious mistakes in Go (empty if blocks? sure!) without the compiler saying anything, and they should just have left that stuff to linters.

I'm afraid I don't know what :zig: is😅

anderseknert,
@anderseknert@hachyderm.io avatar

@shinyzenith Oh, zig :) I just had not seen that logo before.

nemith,
@nemith@hachyderm.io avatar

@anderseknert @shinyzenith Given the evolution of the language and the enhancements in tools and the vet packages over time I think this probably would have been the approach now. There are a lot of critical things that are now Go lints that other languages like Rust would call compiler errors.

_ = myUnusedVar

Works well in the mean time.

anderseknert,
@anderseknert@hachyderm.io avatar

@nemith @shinyzenith Agreed — Go has a tremendous ecosystem of linters, so there's even less need for the compiler to pretend it is one these day. I hope they drop this one day in favor of that.

shinyzenith,

@anderseknert fair point! From what I see, go is like a Swiss army knife of compilers, has a test runner, compiler, generator parser, linter, etc...so I kinda get their motive of having it natively in the language. Cool take tho!

Also, if you haven't heard of zig, tl;dr it's a really cool programming language.

I'm not sure if it's helpful in your domain but for systems developers like myself it's a huge step up over C.
(Didn't notice your follow up message. Hope you enjoy zig :ablobcatheart: )

varfrog,

@anderseknert I add a fmt.Println() statement for that variable if I want to debug it, until I implement real usage of it

anderseknert,
@anderseknert@hachyderm.io avatar

@varfrog Yeah, I think most of us do, and it's just wasting everybody's time IMHO.

jawnsy,
@jawnsy@mastodon.social avatar

@anderseknert I also find it annoying when iterating on code, but I think it can be useful to catch real bugs, and whether something should be fatal or a warning or just info is often a matter of opinion. Nobody will ever agree on the classifications and what's there seems good enough 🤷‍♂️

anderseknert, (edited )
@anderseknert@hachyderm.io avatar

@jawnsy > a matter of opinion
> nobody will ever agree on the classifications

Exactly. That's why linters provide configuration options, and teams/orgs can decide what works for them.

And importantly, they can decide when these things matter to them.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • golang
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cisconetworking
  • rosin
  • thenastyranch
  • Youngstown
  • GTA5RPClips
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • tacticalgear
  • tester
  • osvaldo12
  • modclub
  • normalnudes
  • ngwrru68w68
  • cubers
  • Leos
  • provamag3
  • anitta
  • megavids
  • lostlight
  • All magazines