this post was submitted on 15 Jul 2025
378 points (94.8% liked)

Programmer Humor

37204 readers
899 users here now

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

Rules:

founded 5 years ago
MODERATORS
top 50 comments
sorted by: hot top controversial new old
[–] 6stringringer@lemmy.zip 1 points 23 minutes ago

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

[–] JackbyDev@programming.dev 5 points 1 hour ago

This is why this code is good. Opens MS paint. When I worked at Blizzard-

[–] Treczoks@lemmy.world 1 points 50 minutes ago

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

[–] DrunkAnRoot@sh.itjust.works 1 points 1 hour ago

this is like the making chess one

[–] kreskin@lemmy.world 2 points 1 hour ago

no unit tests huh.

/s

[–] Valmond@lemmy.world 1 points 1 hour ago
[–] sik0fewl@lemmy.ca 4 points 6 hours ago (2 children)

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

[–] Valmond@lemmy.world 1 points 1 hour ago

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

[–] PieMePlenty@lemmy.world 1 points 1 hour 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.

[–] redxef@feddit.org 23 points 10 hours ago (1 children)
def is_even(n: int) -> bool:
    if n < 0:
        return is_even(-n)
    r = True
    for _ in range(n):
        r = not r
    return r
[–] vandsjov@feddit.dk 1 points 2 hours ago

No, no, I would convert the number to a string and just check the last char to see if it was even or not.

[–] Patches@ttrpg.network 9 points 9 hours ago

Y'all laugh but this man has amazing code coverage numbers.

[–] thatradomguy@lemmy.world 5 points 8 hours ago

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

[–] kamen@lemmy.world 18 points 12 hours ago

Plot twist: they used a script to generate that code.

[–] Clbull@lemmy.world 14 points 11 hours ago (1 children)

This is YandereDev levels of bad.

[–] lime@feddit.nu 2 points 8 hours ago (1 children)
[–] segfault11@hexbear.net 16 points 11 hours ago (1 children)

pro hacker tip: you can optimize this by using "num" for the variable name instead of "number"

load more comments (1 replies)
[–] Euphoma@lemmy.ml 19 points 12 hours ago (1 children)
def even(n: int) -> bool:
    code = ""
    for i in range(0, n+1, 2):
        code += f"if {n} == {i}:\n out = True\n"
        j = i+1
        code += f"if {n} == {j}:\n out = False\n"
    local_vars = {}
    exec(code, {}, local_vars)
    return local_vars["out"]

scalable version

[–] xthexder@l.sw0.com 4 points 10 hours ago (1 children)

Not even else if? Damn, I guess we're checking all the numbers every time then. This is what peak performance looks like

[–] lime@feddit.nu 3 points 8 hours ago

O(1) means worst and best case performance are the same.

[–] xorollo@leminal.space 4 points 9 hours ago

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

[–] XPost3000@lemmy.ml 13 points 12 hours ago (1 children)

You don't get it, it runs on a smart fridge so there's no reason to change it

load more comments (1 replies)
[–] pivot_root@lemmy.world 37 points 16 hours ago* (last edited 16 hours ago) (1 children)

That code is so wrong. We're talking about Jason "Thor" Hall here—that function should be returning 1 and 0, not booleans.

If you don't get the joke...In the source code for his GameMaker game, he never uses true or false. It's always comparing a number equal to 1.

[–] Aqarius@lemmy.world 6 points 12 hours ago (2 children)

Frankly, it's what I did, too, after coming out of Uni-level C.

My code was goddamn unreadable.

[–] pivot_root@lemmy.world 3 points 9 hours ago* (last edited 9 hours ago) (1 children)

It's the same for a lot of people. Beginners are still learning good practices for maintainable code, and they're expected to get better over time.

The reason people are ragging on PirateSoftware/Jason/Thor isn't because he's bad at writing code. It's because he's bad at writing code, proclaiming to be an experienced game development veteran, and doubling down and making excuses whenever people point out where his code could be better.

Nobody would have cared if he admitted that he has some areas for improvement, but he seemingly has to flaunt his overstated qualifications and act like the be-all, end-all, know-it-all of video game development. I'm more invested in watching the drama unfold than I should be, but it's hard not to appreciate the schadenfreude from watching arrogant influencers destroy their reputation.

[–] JackbyDev@programming.dev 1 points 1 hour ago

He's totally one of those people that's sort of attractive and has an authoritative voice so s lot of people have probably folded to him in arguments through his life. I don't like making generalizations like that about people but this isn't the first time he's acted like this. The one that really took the cake was the whole hardcore WoW raid debacle.

The TL;DR is, as well as not trying to really spend time on the parts that don't matter, he did some things that may or may not have been the right thing to do in the situation depending on your perspective. But whenever any of his guild mates or other viewers would criticize him he'd be so adamant that no, he didn't do anything wrong, he did exactly what he was supposed to do, etc. People would even explicitly tell him "hey, what's pissing us off now isn't that you did it, it's that you're so adamant you couldn't have possibly made a mistake, you're not willing to see our perspective. You're not willing to admit that maybe you could've been wrong. You're not willing to apologize." And still, his reaction to this was to triple down and just insist he didn't do anything wrong.

Like I literally even saw a clip of him talking to someone and he said "a lot of people think I'm being condescending when really I'm just providing context." And the guy talking to him points out "yeah, it's a problem that you think anyone disagreeing with you doesn't understand the situation, it's like you think they're stupid." It's like it short circuited his brain. It's like he'd never considered it.

So yeah, I have a pretty low opinion of him. But I also recognize that maybe all these clips are taken out of context, who knows. It's not like my opinion really matters. I don't work with him or know him. I don't care about streamers. I don't really watch them.

[–] Croquette@sh.itjust.works 5 points 11 hours ago (1 children)

I am working with C in embedded designs and I still use 1 or 0 for a bool certain situations, mostly lines level.

For whatever pea-brained reason, it feels yucky to me to set a gpio to true/false instead of a 1/0.

[–] xthexder@l.sw0.com 5 points 10 hours ago* (last edited 10 hours ago) (1 children)

GPIOs are usually controlled by a single bit of a register anyway. Most likely you need to do something like:

// Set high
PORTB |= 1 << PINB5;
// Set low
PORTB &= ~(1 << PINB5);
[–] Croquette@sh.itjust.works 2 points 8 hours ago (1 children)

I am a lazy dev (not really, clients always want fast code), so I use the provided HAL libraries 99.9% of the time.

But I have seen code where someone would write something like

gpio_write(PIN_X, true) 

and it always stood out to me.

[–] JackbyDev@programming.dev 1 points 1 hour ago

Define on as true or something? Or maybe that's more confusing. I'm not a C dev so I'm not gonna pretend to understand idiomatic microcontroller code lol.

[–] last_philosopher@lemmy.world 3 points 9 hours 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 2 points 1 hour ago

sleepSort meets sleepIsEven

[–] ferric_carcinization@lemmy.ml 4 points 11 hours 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 5 points 9 hours ago* (last edited 9 hours 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 5 points 10 hours ago

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

[–] olafurp@lemmy.world 13 points 14 hours ago* (last edited 14 hours ago) (1 children)

I'll join in

const isEven = (n) 
  => !["1","3","5","7","9"]
    .includes(Math.round(n).toString().slice(-1)) 
[–] Two9A@lemmy.world 3 points 10 hours ago

I've actually written exactly that before, when I needed to check the lowest bit in an SQL dialect with no bitwise operators. It was disgusting and awesome.

[–] myotheraccount@lemmy.world 96 points 20 hours ago (1 children)

ftfy

bool IsEven(int number) {
  return !IsOdd(number);
}

bool IsOdd(int number) {
  return !IsEven(number);
}
load more comments (1 replies)
load more comments
view more: next ›