1426
Golang be like (i.imgur.com)
you are viewing a single comment's thread
view the rest of the comments
[-] HiddenLayer5@lemmy.ml 85 points 1 year ago* (last edited 1 year ago)

Sometimes I think Go was specifically made for Google to dictate its own preferences on the rest of us like some kind of power play. It enforces one single style of programming too much.

[-] space_comrade@hexbear.net 21 points 1 year ago

From what I've heard from Google employees Google is really stringent with their coding standards and they usually limit what you can do with the language. Like for C++ they don't even use half the fancy features C++ offers you because it's hard to reason about them.

I guess that policy makes sense but I feel like it takes out all the fun out of the job.

[-] frezik@midwest.social 18 points 1 year ago

As far as C++ goes, that's probably the only sane way to use the language.

[-] Sloogs@lemmy.dbzer0.com 9 points 1 year ago* (last edited 1 year ago)

Just about any place I know that uses C++ also does that with C++ so that's nothing unusual for C++ specifically. It's too big of a language to reason about very well if you don't, so you've gotta find a subset that works.

[-] skeletorsass@hexbear.net 1 points 1 year ago

Too many patterns. If you do not do this every author will have a different use of the language and you will have to read a book of documentation each time you change files.

[-] philm@programming.dev 18 points 1 year ago

Is this a hard error? Like it doesn't compile at all?

Isn't there something like #[allow(unused)] in Rust you can put over the declaration?

[-] flame3244@lemmy.world 27 points 1 year 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@sh.itjust.works 29 points 1 year ago

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

[-] flame3244@lemmy.world 2 points 1 year 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.

[-] AeonFelis@lemmy.world 12 points 1 year ago* (last edited 1 year 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@sh.itjust.works 9 points 1 year 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.

[-] AstridWipenaugh@lemmy.world 5 points 1 year ago* (last edited 1 year 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.

[-] HiddenLayer5@lemmy.ml 12 points 1 year ago* (last edited 1 year ago)

Never really coded in Go outside of trying it out, but as far as I know it's a hard error.

[-] flame3244@lemmy.world 8 points 1 year ago

I think this is a good thing. The styles are just opinions anyway and forcing everyone to just follow a single style takes a lot of bikeshedding away, which I really like.

this post was submitted on 14 Aug 2023
1426 points (100.0% liked)

Programmer Humor

19480 readers
329 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS