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

Programmer Humor

37235 readers
34 users here now

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

Rules:

founded 5 years ago
MODERATORS
(page 2) 50 comments
sorted by: hot top controversial new old
[–] VibeCoder@hexbear.net 17 points 2 days ago

Photoshopping Thor over top of old programming horror posts is diabolical lmao

[–] WraithGear@lemmy.world 1 points 1 day ago* (last edited 1 day ago) (4 children)

Would this be a case of modulo saving the day?

Like: If Number modulo 2 = 0, true

This has to be taken out of context

load more comments (4 replies)
[–] huf@hexbear.net 17 points 2 days ago

pff, i aint reading all that, lemme optimize it:

private bool isEven(int number) {
    return rand() < 0.5;
}
[–] FishFace@lemmy.world 18 points 2 days ago (5 children)

This is what Test Driven Development looks like

[–] normalexit@lemmy.world 13 points 2 days ago (11 children)

TDD has cycles of red, green, refactor. This has neither been refactored nor tested. You can tell by the duplication and the fact that it can't pass all test cases.

If this looks like TDD to you, I'm sorry that is your experience. Good results with TDD are not guaranteed, you still have to be a strong developer and think through the solution.

load more comments (11 replies)
load more comments (4 replies)
[–] Gladaed@feddit.org 14 points 2 days ago

Ffs just use a switch. It's much faster!

[–] xorollo@leminal.space 5 points 2 days ago

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

[–] 6stringringer@lemmy.zip 2 points 1 day ago

Thanks to goodness, finally. A (giggle & snort) solid algorithm. There ya’s go set yer clocks & go get a haircut.

[–] voodooattack@lemmy.world 7 points 2 days ago* (last edited 2 days ago)
bool isEven(int value) {
  return (int)(((double)value / 2.0) % 1.0) * 100) != 50;
} 
[–] DrunkAnRoot@sh.itjust.works 2 points 1 day ago

this is like the making chess one

[–] thann@lemmy.dbzer0.com 9 points 2 days 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 2 days 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.

[–] thann@lemmy.dbzer0.com 4 points 2 days ago

What should all the non binary people do then you bigot

[–] theherk@lemmy.world 4 points 2 days ago

Wasn’t the fun the CPU cycles we wasted along the way?

load more comments (5 replies)
[–] last_philosopher@lemmy.world 4 points 2 days ago (1 children)

To be fair, the question is "Write a function that simultaneously determines if the number is even and works as a timer"

[–] JackbyDev@programming.dev 3 points 1 day ago

sleepSort meets sleepIsEven

[–] elvith@feddit.org 11 points 2 days ago* (last edited 2 days ago)
assert IsEven(-2);
[–] ferric_carcinization@lemmy.ml 4 points 2 days ago (2 children)

I hope that the language's ints are at most 32 bits. For 8 bits it could even be written by hand & the source code for a 32 bit version would only take up avg_line_len * 4GiB space for the source code of the function. But it might take a bit of time to compile a version that supports the full range of 64 or 128 bit ints.

[–] Patches@ttrpg.network 6 points 2 days ago* (last edited 2 days ago)

My mate, Paul, says all numbers after 700 repeat so we can stop there.

We just give them different names so you think they're going up.

[–] segfault11@hexbear.net 6 points 2 days ago

all you have to to is throw an exception if the number is bigger than 100, who even needs numbers that big anyways?

[–] TankieTanuki@hexbear.net 9 points 2 days ago

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

load more comments
view more: ‹ prev next ›