164
// Implement (lemmy.zip)
submitted 1 week ago by [email protected] to c/[email protected]
top 22 comments
sorted by: hot top new old
[-] [email protected] 40 points 1 week ago
[-] [email protected] 15 points 1 week ago

So one understood the assignment.

[-] [email protected] 34 points 1 week ago

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.

[-] [email protected] 24 points 1 week ago

that's why c++ gets bullied

[-] [email protected] 6 points 1 week ago

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

[-] [email protected] 21 points 1 week ago

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.

[-] [email protected] 2 points 1 week ago* (last edited 1 week 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

[-] [email protected] 1 points 1 week ago

You wouldn't second guess the decrement operation if it's a basic type like int. If I opt into using complex types, then I am responsible to understand/establish/forbid the syntactic sugar for it. That's the mindset I often use to program C++

[-] [email protected] 15 points 1 week ago

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

[-] [email protected] 5 points 1 week ago

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

[-] [email protected] 2 points 1 week ago

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

[-] [email protected] 15 points 1 week ago

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.

[-] [email protected] 3 points 1 week 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.

[-] [email protected] 6 points 1 week 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.)

[-] [email protected] 10 points 1 week ago

a logical skeuomorphism, how eccentric

[-] [email protected] 3 points 1 week ago

Haha! I had the same thought.

[-] [email protected] 8 points 1 week ago* (last edited 1 week ago)

Thank goodness for the JIT and compiler optimizations.

[-] [email protected] 2 points 1 week ago

...would JIT optimizations even help here?

[-] [email protected] 7 points 1 week ago

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

[-] [email protected] 2 points 1 week ago* (last edited 1 week ago)
this post was submitted on 01 Aug 2025
164 points (99.4% liked)

Programmer Humor

25699 readers
1342 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