this post was submitted on 15 Jul 2025
461 points (94.9% liked)

Programmer Humor

37339 readers
443 users here now

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

Rules:

founded 6 years ago
MODERATORS
(page 2) 50 comments
sorted by: hot top controversial new old
[–] sik0fewl@lemmy.ca 10 points 1 week ago (2 children)

This code would run a lot faster as a hash table look up.

[–] PieMePlenty@lemmy.world 6 points 1 week ago

I agree. Just need a table of even numbers. Oh and a table of odd numbers, of course, else you cant return the false.. duh.

[–] Valmond@lemmy.world 5 points 1 week ago

In a Juliana tree, or a dictionary tree if you want. For speed.

[–] thann@lemmy.dbzer0.com 9 points 1 week ago (1 children)

You could use a loop to subtract 2 from the number until it equals one or zero

[–] TimeSquirrel@kbin.melroy.org 8 points 1 week ago (7 children)

Or literally just look at its binary representation. If the least significant digit is a "1", it's odd, if "0", it's even. Or you can divide by 2 and check for a remainder.

Your method is just spending time grinding away CPU cycles for no reason.

load more comments (7 replies)
[–] TankieTanuki@hexbear.net 9 points 1 week ago

No need to reinvent the wheel. Use the isEven API!

[–] thatradomguy@lemmy.world 9 points 1 week ago

Can you imagine being a TA and having to grade somebody's hw and you get this first thing? lmao

[–] kreskin@lemmy.world 8 points 1 week ago

no unit tests huh.

/s

[–] RustyNova@lemmy.world 8 points 1 week ago (2 children)
load more comments (2 replies)
[–] voodooattack@lemmy.world 7 points 1 week ago* (last edited 1 week ago)
bool isEven(int value) {
  return (int)(((double)value / 2.0) % 1.0) * 100) != 50;
} 
[–] ClathrateG@hexbear.net 7 points 1 week ago* (last edited 1 week ago) (1 children)

apart from everything else, have they never heard of a switch statement

[–] roux@hexbear.net 8 points 1 week ago

Switch statements is the next lesson in this bootcamp.

[–] AlyxMS@hexbear.net 7 points 1 week ago (2 children)

What you do is use a for loop to generate a million lines for you, then paste it in. Writing it manually is moronic. You can easily make it support numbers above 1,000,000 too this way, talking about scalable

load more comments (2 replies)
[–] Kuma@lemmy.world 6 points 1 week ago

I am more amazed that he didn't stop at 10 and think "damn this is tiresome isn't there a one liner i could do?". I want to know how far he went. His stubbornness is amazing but also scary. I haven't seen this kind of code since back in school lol lol lol

[–] Treczoks@lemmy.world 6 points 1 week ago

Good if you are rated by an AI that pays for LOCs.

[–] FireIced@lemmy.super.ynh.fr 5 points 1 week ago

that's some good code right there

[–] Midnitte@beehaw.org 5 points 1 week ago

When did Thor become the dev for Yandere Simulator?

[–] xorollo@leminal.space 5 points 1 week ago

This joke was not written by the dude pictured. The author wrote a book of funny code jokes.

load more comments
view more: ‹ prev next ›