465
Peak code reuse (eviltoast.org)
all 40 comments
sorted by: hot top controversial new old
[-] cupcakezealot@piefed.blahaj.zone 56 points 1 month ago* (last edited 1 month ago)
bool isOdd(int num) {  
	const oddNumbers = [];  
	for (let i = 1; i <= 10000000; i += 2) {  
  		oddNumbers.push(i);  
	}  
	if (oddNumbers.includes(num) {  
		return true;  
	}  
}  
[-] Malix@sopuli.xyz 19 points 1 month ago
[-] moseschrute@piefed.social 11 points 1 month ago* (last edited 1 month ago)

Maybe memo just to be safe, but LGTM!

[-] cupcakezealot@piefed.blahaj.zone 21 points 1 month ago

this incident has been reported

[-] marcos@lemmy.world 4 points 1 month ago

You should make it oddNumbers.includes(num%10000000)...

[-] schema@lemmy.world 1 points 1 month ago

And if not, unicorns!

[-] meme_historian@lemmy.dbzer0.com 54 points 1 month ago
[-] Valmond@lemmy.world 3 points 1 month ago

Oh, Python!

[-] a14o@feddit.org 50 points 1 month ago

To fix this, add if(num == 255) return true; before line 10.

[-] CannonFodder@lemmy.world 24 points 1 month ago

Peak efficiency there.

But use 2147483647 to be safe.

[-] HappyFrog 47 points 1 month ago

Will this ever return? Won't it just overflow the stack?

[-] sjmarf@sh.itjust.works 77 points 1 month ago

Yep, this will cause a stack overflow.

[-] rovingnothing29@lemmy.world 32 points 1 month ago

A mod will appear in my office and claim my problem is a duplicate when it's not?

[-] Mad_Punda@feddit.org 24 points 1 month ago* (last edited 1 month ago)

Might very well be an endless loop because tail recursion can be optimized to reuse the stack frame. Depends on a lot of things of course.

[-] MonkderVierte@lemmy.zip 5 points 1 month ago* (last edited 1 month ago)

~~Hm, stack overflow is basically a forkbomb in programming?~~ ok, bullshit.

[-] orhtej2@eviltoast.org 21 points 1 month ago

Forkbomb kills the entire system so not really.

With the stack overflow the runtime will gracefully terminate the program.

[-] Valmond@lemmy.world 1 points 1 month ago

Program it with template meta programming and cause a stack overflow when compiling 🤓😎

[-] OpenStars@piefed.social 23 points 1 month ago

Boss: don't spend any time on it, just vibe code a solution.

You: sure, I enjoy receiving a salary, what could go wrong?

[-] Aneb@lemmy.world 1 points 1 month ago
[-] FiskFisk33@startrek.website 19 points 1 month ago

https://www.npmjs.com/package/is-even

don't look at the weekly downloads if you are faint of heart.

[-] Decq@lemmy.world 11 points 1 month ago* (last edited 1 month ago)

To be fair in a dynamic typed language with dumb string to int coercions, I kinda get why such a library would exists. So it's more a symptom of terrible language design than modern dependency hell.

[-] bobo@lemmy.ml 9 points 1 month ago* (last edited 1 month ago)

in a dynamic typed language with dumb string to int coercions, I kinda get why such a would library exists.

If string return nan, else % 2

So it's more a symptom of terrible language design than modern dependency hell.

Dependency chain: is-even depends on is-odd which depends on is-number

[-] Decq@lemmy.world 2 points 1 month ago* (last edited 1 month ago)

If string return nan, else % 2

So now you return a number type if it's a string and a boolean if it's an integer. How does that make sense?

The is-even lib exists to sanitize input by throwing an exception which imho is better.

Edit: having looked at the code better. Apparently it still allows string coercion (boo). It only checks for non integer numbers.

[-] bobo@lemmy.ml 1 points 1 month ago

Good point, but you can do if === true... and else if === false...

But definitely better to throw an error instead of nan.

[-] Hawk@lemmy.dbzer0.com 6 points 1 month ago

If you really want to see some horror, follow the dependencies

[-] ThanksForAllTheFish@sh.itjust.works 3 points 1 month ago* (last edited 1 month ago)

https://10xengineersqualityprogramming.github.io/ https://www.npmjs.com/package/@falsejs/falsejs This is hilarious, has 262 of the best useless dependencies. In all seriousness though how does anyone ever audit a npm package, it's dependency hell!

[-] cogman@lemmy.world 7 points 1 month ago* (last edited 1 month ago)

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);
}
[-] affiliate@lemmy.world 11 points 1 month ago

the downside with this approach is that it will eventually terminate. the version in the original post has the advantage of giving me plenty of time to contemplate life’s many mysteries.

[-] cogman@lemmy.world 4 points 1 month ago

What can I say, I'm a performance nerd.

[-] Valmond@lemmy.world 1 points 1 month ago

isEeven(∞);

[-] FiskFisk33@startrek.website 5 points 1 month ago* (last edited 1 month ago)
isEven(0) ->
    true;
isEven(Num) ->
    isOdd(Num-1).
isOdd(0) ->
    false;
isOdd(Num) ->
    isEven(Num-1).
[-] mercano@lemmy.world 4 points 1 month ago

When it fails, it at least points you to the site where everyone asks for help.

[-] orhtej2@eviltoast.org 3 points 1 month ago

Closed as unclear

[-] humanspiral@lemmy.ca 2 points 1 month ago* (last edited 1 month ago)

easy fix... if infinity return false.

mathematical breakthrough bonus proof: all numbers are neither even nor odd.

this post was submitted on 12 Sep 2025
465 points (100.0% liked)

Programmer Humor

27193 readers
1255 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