this post was submitted on 14 Aug 2023
1321 points (98.0% liked)

Programmer Humor

24834 readers
157 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 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] DarkDarkHouse@lemmy.sdf.org 191 points 2 years ago (5 children)

As your future colleague wondering what the hell that variable is for, thanks Go.

[–] Willem@kutsuya.dev 63 points 2 years ago

I prefer for it to be just a warning so I can debug without trouble, the build system will just prevent me from completing the pull request with it (and any other warning).

[–] iforgotmyinstance@lemmy.world 40 points 2 years ago

Changing it will bring down the entire system.

We've spent ten million dollars and do not know why.

[–] Nioxic@lemmy.world 26 points 2 years ago (1 children)

Isnt the syntax highlighting it as mever used?

So why would they wonder?

load more comments (1 replies)
[–] MJBrune@beehaw.org 25 points 2 years ago (3 children)

A quick "find all references" will point out it's not used and can be deleted if it accidentally gets checked in but ideally, you have systems in place to not let it get checked into the main branch in the first place.

[–] Flarp@kbin.social 27 points 2 years ago

Yeah that should be looked for in a CI line check, not a compilation requirement

[–] aport@programming.dev 9 points 2 years ago (1 children)

You mean a system like the compiler

[–] MJBrune@beehaw.org 14 points 2 years ago* (last edited 2 years ago) (2 children)

Or a linter. Or code reviews. Or anything else. The nice thing is that if the compiler doesn't demand something, it can be given to the engineer as an option. The compiler should have the option to do it. The option could even be defaulted on. Afaik there is no way in Golang to disable that error (this is the line that does it: https://github.com/golang/go/blob/04fb929a5b7991ed0945d05ab8015c1721958d82/src/go/types/stmt.go#L67-L69). like --no-pedantics or such. Golang's compiler openly refuses to give engineers more choices in what they think is the best system to handle it.

load more comments (2 replies)
load more comments (1 replies)
[–] ennemi@hexbear.net 18 points 2 years ago* (last edited 2 years ago) (3 children)

If only there was some way the compiler could detect unused variable declarations, and may be emit some sort of "warning", which would be sort of like an "error", but wouldn't cause the build to fail, and could be treated as an error in CI pipelines

load more comments (3 replies)
[–] HiddenLayer5@lemmy.ml 74 points 2 years ago* (last edited 2 years ago) (3 children)

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 17 points 2 years ago (3 children)

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 15 points 2 years ago

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

load more comments (2 replies)
[–] philm@programming.dev 17 points 2 years ago (2 children)

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 2 years ago (3 children)

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.

load more comments (3 replies)
[–] HiddenLayer5@lemmy.ml 12 points 2 years ago* (last edited 2 years ago)

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

load more comments (1 replies)
[–] fkn@lemmy.world 47 points 2 years ago (1 children)

Also Go: exceptions aren't real, you declare and handle every error at every level or declare that you might return that error because go fuck yourself.

[–] zorro@lemmy.world 52 points 2 years ago (3 children)

Because that's sane and readable?

[–] fkn@lemmy.world 31 points 2 years ago (3 children)

Wow. I'm honestly surprised I'm getting downvotes for a joke. Also, no. It isn't. It really isn't.

load more comments (3 replies)
[–] r1veRRR@feddit.de 19 points 2 years ago (1 children)

It's better than "invisible" exceptions, but it's still the worst "better" version. The best solution is some version of the good old Result monad. Rust has the BEST error handling (at least in the languages i know). You must handle Errors, BUT they are just values, AND there's a easy, non-verbose way of passing on the error (the ? operator).

load more comments (1 replies)
load more comments (1 replies)
[–] CodeBlooded@programming.dev 46 points 2 years ago* (last edited 2 years ago) (10 children)

If this language feature is annoying to you, you are the problem. You 👏are 👏 the 👏 reason 👏 it 👏 exists.

I worked in places where the developers loaded their code full of unused variables and dead code. It costs a lot of time reasoning about it during pull request and it costs a lot of time arguing with coworkers who swear that they’re going to need that code in there next week (they never need that code).

This is a very attractive feature for a programming language in my opinion.

PS: I’m still denying your pull request if you try to comment the code instead.

❗️EDIT: A lot of y’all have never been to programming hell and it shows. 🪖 I’m telling you, I’ve fixed bayonets in the trenches of dynamically typed Python, I’ve braved the rice paddies of CICD YAML mines, I’ve queried alongside SQL Team Six; I’ve seen things in production, things you’ll probably never see… things you should never see. It’s easy to be against an opinionated compiler having such a feature, but when you watch a prod deployment blow up on a Friday afternoon without an easy option to rollback AND hours later you find the bug after you were stalled by dead code, it changes you. Then… then you start to appreciate opinionated features like this one. 🫡

[–] m_f@midwest.social 72 points 2 years ago (7 children)

That's 👏 what 👏 CI 👏 is 👏 for

Warn in dev, enforce stuff like this in CI and block PRs that don't pass. Go is just being silly here, which is not surprising given that Rob Pike said

Syntax highlighting is juvenile. When I was a child, I was taught arithmetic using colored rods. I grew up and today I use monochromatic numerals.

The Go developers need to get over themselves.

[–] WhyEssEff@hexbear.net 13 points 2 years ago (1 children)

reading my code after being up for 18 hours and having my eyes glaze over trying to parse the structure of my monochromatic code but then I remember Rob Pike said syntax highlighting is juvenile so I throw my head against that wall for another 3 hours

[–] WhyEssEff@hexbear.net 12 points 2 years ago* (last edited 2 years ago)

Prescription glasses are juvenile. When I was a child, I was prescribed visual aid to help my nearsightedness. I grew up and today I raw-dog the road.

load more comments (6 replies)
[–] Urik@lemmy.ca 52 points 2 years ago* (last edited 2 years ago) (2 children)

That's a problem with your workplace, not the language nor OP.
You could have a build setting for personal development where unused variables are not checked, and then a build setting for your CI system that will look for them. It gives you freedom to develop the way you want without being annoyed when you remove something just to test something, but will not merge your PR unless the stricter rules are met.

load more comments (2 replies)
[–] AeonFelis@lemmy.world 26 points 2 years ago

That's what warnings are for. The jokes about programmers ignoring warnings are outdated - we live in an age where CIs run linters and style checkers on pull requests, there is no reason for a CI to not automatically reject code that builds with warnings.

[–] pixeltree@lemmy.world 23 points 2 years ago (1 children)

I mean, yeah that kind of stuff absolutely should not be in production. However, it's easy to see how it could be annoying while testing something while working on it. It being annoying doesn't make it a bad feature, just as finding it annoying doesn't make you a problem imo.

load more comments (1 replies)
[–] thanks_shakey_snake@lemmy.ca 20 points 2 years ago (1 children)

Lol new copypasta unlocked 🔓

load more comments (1 replies)
[–] redcalcium@lemmy.institute 14 points 2 years ago

It costs a lot of time reasoning about it during pull request and it costs a lot of time arguing with coworkers who swear that they’re going to need that code in there next week (they never need that code).

You should go to your team leader and ask them to enforce a coding standard. I agree with other commenters that said this should be a warning instead of an error.

load more comments (4 replies)
[–] NatoBoram@lemm.ee 33 points 2 years ago (1 children)

And I fucking love it. Thank you Go!

[–] lightsecond@programming.dev 29 points 2 years ago
[–] ytrav@lemmy.world 28 points 2 years ago

lints that underline unused vars as errors, and not notes or warns are the worst lints..

[–] jeanma@lemmy.ninja 21 points 2 years ago

OP never said he/she commits such code but wants to iterate, test, explore.

Of course, unused var should not be part of a commit.

[–] yum13241@lemm.ee 19 points 2 years ago (1 children)

This makes me not want to use Golang at all.

[–] AstridWipenaugh@lemmy.world 9 points 2 years ago

I assure you, the feeling is mutual.

[–] fauxerious@lemmy.world 17 points 2 years ago

you can assign it to itself and it’ll be just fine. can’t put a breakpoint right on it, but it works

[–] Rednax@lemmy.world 13 points 2 years ago (1 children)

I hate this in C++ when it does this with parameters of an overidden function. I don't need that specific parameter, but if I omit the variable name, I reduce readability.

[–] Dienes@lemmy.world 8 points 2 years ago (1 children)
load more comments (1 replies)
[–] Agent641@lemmy.world 12 points 2 years ago

Me when my wife wants to buy new clothes (her clothes are the variables)

[–] Crashumbc@lemmy.world 11 points 2 years ago

The best part of these threads is no matter what someone comments, at least 2 people will reply either correcting or "clarifying" the original commenter.

Lol

[–] MonkderZweite@feddit.ch 10 points 2 years ago

Comment the unused variable out and no security hole gets accidentally shipped.

load more comments
view more: next ›