this post was submitted on 22 Oct 2023
2 points (100.0% liked)

Programmer Humor

35334 readers
1 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
 
top 6 comments
sorted by: hot top controversial new old
#define max(x,y) ( { __auto_type __x = (x); __auto_type __y = (y); __x > __y ? __x : __y; })

GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn't I'd replace the ternary with the "bit hacker 2" version.

[–] lwhjp@lemmy.sdf.org 1 points 2 years ago

TDD

const max12 = (x, y) => {
    if (x === 1 && y === 2) {
        return 2;
    } else if (x === 7 && y === 4) {
        return 7;
    } else {
        return x;
    }
};
[–] SuperIce@lemmy.world 0 points 2 years ago (1 children)

Why would you use anything other than Math.max?

[–] SzethFriendOfNimi@lemmy.world 1 points 2 years ago

Some of us have trust issues. Or worked with Java.

Which, now that I think about it, comes to the same thing.

[–] Fungah@lemmy.world 0 points 2 years ago (1 children)

Reminded of how truly little I know about programming despite the time have spent doing it

Ugh. I'll never be any good.

[–] Theharpyeagle@lemmy.world 1 points 2 years ago

Listen, in industry programming (and for personal projects if you want to get them done), the thief is the way to go. By all means, challenge yourself to understand each of these functions, but 99% of day to day development will not look like this.