this post was submitted on 15 Jul 2025
279 points (94.3% liked)

Programmer Humor

25448 readers
930 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
[–] sus@programming.dev 87 points 2 weeks ago* (last edited 2 weeks ago) (9 children)

After working at blizzard for 51 years, I finally found an elegant solution by using the power of recursion

private bool IsEven(int number){
  if (number > 1) return IsEven(number - 2);
  if (number == 0) return true;
  if (number == 1) return false;
}
[–] elvith@feddit.org 40 points 2 weeks ago (3 children)
[–] lambda@programming.dev 14 points 2 weeks ago (1 children)

Now see, you need the other method. IsNegativeEven()

[–] sus@programming.dev 9 points 2 weeks ago (1 children)

We can avoid expensive branches (gasp) by using some bitwise arithmetic to achieve the so-called "absolute value", an advanced hacker technique I learnt at Blizzard. Also unlike c, c# is not enlightened enough to understand that my code is perfect so it complains about "not all code paths returning a value".

private bool IsEven(int number)
{
    number *= 1 - 2*(int)(((uint)number & 2147483648) >> 31);
    if (number > 1) return IsEven(number - 2);
    if (number == 0) return true;
    if (number == 1) return false;
    throw new Exception();
}
[–] UnknownSoul@programming.dev 2 points 2 weeks ago

Nice, now we just need another function to find odd numbers, cause not all numbers are even you know.

load more comments (1 replies)
load more comments (6 replies)