this post was submitted on 01 Aug 2025
156 points (99.4% liked)

Programmer Humor

25425 readers
1301 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
all 22 comments
sorted by: hot top controversial new old
[–] MyTurtleSwimsUpsideDown@fedia.io 35 points 1 day ago (1 children)
[–] KairuByte@lemmy.dbzer0.com 12 points 1 day ago

So one understood the assignment.

[–] Lembot_0004@discuss.online 38 points 1 day ago (3 children)

It might be an absolutely adequate method. Imagine that is C++. operator-- is overloaded and controls some machinery. You can't just command capacity = currSize. Process is important.

[–] marcos@lemmy.world 16 points 1 day ago (1 children)

Yeah, just to say it more clearly: that kind of thing is why lots of people out there insist that operator overloading is a bad idea.

And yeah, it's a C++ thing that mostly doesn't happen in other languages.

[–] TeamAssimilation 2 points 22 hours ago

Sincerely agree. Explicit is better then implicit, that’s a general engineering axiom.

Instead of overloading and making the next maintainer hunt for overloads, a clearly named function that does the critical steps would make the code immensely more maintainable. C++ is C gone wild.

[–] eager_eagle@lemmy.world 23 points 1 day ago (1 children)

that's why c++ gets bullied

[–] Lembot_0004@discuss.online 7 points 1 day ago (3 children)

That is why it is loved: it allows you to use ideas/objects the same way as you do as an engineer. Super cool.

[–] CanadaPlus@lemmy.sdf.org 14 points 1 day ago

Until the next person with a slightly different mental way of defining things comes along. Or just a future version of you.

[–] eager_eagle@lemmy.world 16 points 1 day ago (3 children)

yes, but in this particular case I wouldn't want to second guess my decrement operation just happens to also be calling the white house or whatnot. Just make a method.

[–] SpaceNoodle@lemmy.world 6 points 1 day ago (1 children)
[–] leo85811nardo@lemmy.world 2 points 1 day ago* (last edited 1 day ago)

That's just life of a C++ programmer: you second guess everything, and there are still optimization you haven't tried, and pitfalls you haven't got into

[–] mkwt@lemmy.world 5 points 1 day ago (1 children)

But when you do shoot yourself in the foot, it blows your whole leg off.

[–] Lembot_0004@discuss.online 2 points 1 day ago

As a shotgun. That's why people don't shoot themselves in the foot with a shotgun.

[–] melechric@lemmy.world 7 points 1 day ago

Yes. Sometimes you're limited by the hardware you're controlling. This code is a bit hard to justify with that excuse though. Normally your code would do a read from hardware to see if the value decremented and then repeat the write. (Possibly a sleep/yield in there if required.)

[–] joyjoy@lemmy.zip 10 points 1 day ago* (last edited 1 day ago) (1 children)

Thank goodness for the JIT and compiler optimizations.

[–] isVeryLoud@lemmy.ca 2 points 14 hours ago

...would JIT optimizations even help here?

[–] eager_eagle@lemmy.world 13 points 1 day ago (1 children)

a logical skeuomorphism, how eccentric

[–] mobotsar@sh.itjust.works 3 points 1 day ago

Haha! I had the same thought.

[–] anton@piefed.blahaj.zone 8 points 1 day ago (1 children)

If those are normal integers, the compiler optimizes that to a simple compare and branch/cmov.

[–] eager_eagle@lemmy.world 2 points 1 day ago* (last edited 1 day ago)