A stack overflow is a symptom, not the illness. A fork bomb is an illness.
Software coming from the mathematical point of view, assummes it has infinite resources. However, a real computer has many resources that are finite.
CPU time is finite. Memory amount is finite. There is a finite number of network ports. And so on.
A stack overflow just means: "you have run out of this resource called 'the stack'". The stack is a region of the memory. Each thread of each process has 1 stack, and it is not infinite in size. This program will cause a stack overflow because it is infinitely recursive, and each function call will consume a bit of the stack.
A forkbomb is not the end of a finite resource. A fork bomb is a program that uses "forking" to rapidly consume system resources. A fork bomb might cause a stack overflow. Or an out of memory issue. Slow the computer a lot. Or if the OS has a hard limit for process amount, it might reach that limit.
A program such as the one in this post is a loop designed (intentionally or not) to run out of stack regardless of how much there is. I'd call that an illness rather than a symptom.
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.
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.
Nah, tail recursion optimization can just reuse the same stack frame again and again. It's going to loop until it wraps around what ever integer width it has and then tells you if the biggest integer is even or odd. Or, if it's nice, it's going to complain about the wrap around
41 Comments
cupcakezealot@piefed.blahaj.zone · 55 pts · 357d
Malix@sopuli.xyz · 18 pts · 357d
dev_null@lemmy.ml · 1 pts · 356d
moseschrute@piefed.social · 10 pts · 357d
Maybe memo just to be safe, but LGTM!
dependencyinjection@discuss.tchncs.de · 10 pts · 356d
isOdd(10000001);
cupcakezealot@piefed.blahaj.zone · 20 pts · 356d
this incident has been reported
marcos@lemmy.world · 4 pts · 356d
You should make it
oddNumbers.includes(num%10000000)...schema@lemmy.world · 1 pts · 356d
And if not, unicorns!
meme_historian@lemmy.dbzer0.com · 53 pts · 356d
Valmond@lemmy.world · 3 pts · 356d
Oh, Python!
a14o@feddit.org · 51 pts · 357d
To fix this, add
if(num == 255) return true;before line 10.CannonFodder@lemmy.world · 25 pts · 357d
Peak efficiency there.
But use 2147483647 to be safe.
HappyFrog@lemmy.blahaj.zone · 48 pts · 357d
Will this ever return? Won't it just overflow the stack?
sjmarf@sh.itjust.works · 80 pts · 357d
Yep, this will cause a stack overflow.
rovingnothing29@lemmy.world · 34 pts · 357d
A mod will appear in my office and claim my problem is a duplicate when it's not?
Mad_Punda@feddit.org · 25 pts · 357d
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 · 3 pts · 357d
Hm, stack overflow is basically a forkbomb in programming?ok, bullshit.orhtej2@eviltoast.org · 22 pts · 357d
Forkbomb kills the entire system so not really.
With the stack overflow the runtime will gracefully terminate the program.
calcopiritus@lemmy.world · 12 pts · 357d
No.
A stack overflow is a symptom, not the illness. A fork bomb is an illness.
Software coming from the mathematical point of view, assummes it has infinite resources. However, a real computer has many resources that are finite.
CPU time is finite. Memory amount is finite. There is a finite number of network ports. And so on.
A stack overflow just means: "you have run out of this resource called 'the stack'". The stack is a region of the memory. Each thread of each process has 1 stack, and it is not infinite in size. This program will cause a stack overflow because it is infinitely recursive, and each function call will consume a bit of the stack.
A forkbomb is not the end of a finite resource. A fork bomb is a program that uses "forking" to rapidly consume system resources. A fork bomb might cause a stack overflow. Or an out of memory issue. Slow the computer a lot. Or if the OS has a hard limit for process amount, it might reach that limit.
davidgro@lemmy.world · 1 pts · 356d
A program such as the one in this post is a loop designed (intentionally or not) to run out of stack regardless of how much there is. I'd call that an illness rather than a symptom.
ozymandias117@lemmy.world · 1 pts · 356d
Valmond@lemmy.world · 2 pts · 356d
Program it with template meta programming and cause a stack overflow when compiling 🤓😎
OpenStars@piefed.social · 24 pts · 356d
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 pts · 356d
Mood...
FiskFisk33@startrek.website · 19 pts · 356d
https://www.npmjs.com/package/is-even
don't look at the weekly downloads if you are faint of heart.
Decq@lemmy.world · 10 pts · 356d
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 pts · 356d
If string return nan, else % 2
Dependency chain: is-even depends on is-odd which depends on is-number
Decq@lemmy.world · 1 pts · 356d
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.
Decq@lemmy.world · 1 pts · 356d
bobo@lemmy.ml · 1 pts · 356d
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 pts · 356d
If you really want to see some horror, follow the dependencies
ThanksForAllTheFish@sh.itjust.works · 3 pts · 356d
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 pts · 356d
Fixed
affiliate@lemmy.world · 11 pts · 356d
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 pts · 356d
What can I say, I'm a performance nerd.
Rednax@lemmy.world · 1 pts · 356d
Why the complicated if statements to check the sign? Just let the number overflow. Would be functionaly the same, and result in much prettier code.
cogman@lemmy.world · 6 pts · 356d
That's a platform dependent change. Overflow is undefined behavior. I'd rather have my code portable so it can run on my Univac 1101.
Valmond@lemmy.world · 1 pts · 356d
isEeven(∞);
FiskFisk33@startrek.website · 6 pts · 356d
Knock_Knock_Lemmy_In@lemmy.world · 3 pts · 356d
Hmm.
isEven(-2)...<out of stack error>
killingspark@feddit.org · 3 pts · 356d
Nah, tail recursion optimization can just reuse the same stack frame again and again. It's going to loop until it wraps around what ever integer width it has and then tells you if the biggest integer is even or odd. Or, if it's nice, it's going to complain about the wrap around
mercano@lemmy.world · 4 pts · 356d
When it fails, it at least points you to the site where everyone asks for help.
orhtej2@eviltoast.org · 3 pts · 356d
Closed as unclear
humanspiral@lemmy.ca · 2 pts · 355d
easy fix... if infinity return false.
mathematical breakthrough bonus proof: all numbers are neither even nor odd.
guthib_net@programming.dev · 0 pts · 356d
guthib_net@programming.dev · -1 pts · 356d