this post was submitted on 12 Sep 2025
459 points (98.7% liked)

Programmer Humor

26391 readers
1930 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] cogman@lemmy.world 7 points 5 days ago* (last edited 5 days ago) (5 children)

Fixed

boolean isOdd(int num) {
  if(num == 1)
    return true;
  if(num > 0)
    return isEven(num - 1);
  else
    return isEven(num + 1);
}

boolean isEven(int num) {
  if(num > 0)
    return isOdd(num - 1);
  else
    return isOdd(num + 1);
}
[–] Rednax@lemmy.world 1 points 5 days ago (1 children)

Why the complicated if statements to check the sign? Just let the number overflow. Would be functionaly the same, and result in much prettier code.

[–] cogman@lemmy.world 6 points 5 days ago

That's a platform dependent change. Overflow is undefined behavior. I'd rather have my code portable so it can run on my Univac 1101.

load more comments (3 replies)