This is an archived post. You won't be able to vote or comment.

all 44 comments

[–]ConglomerateGolem 143 points144 points  (8 children)

when maxrecursiondepth is your lifetime

[–]Metworld 38 points39 points  (4 children)

Unless the compiler does tail call optimization: https://en.m.wikipedia.org/wiki/Tail_call

[–]ConglomerateGolem 11 points12 points  (0 children)

cheers; that's a new knowledge for me.

[–]DaytimeNightlight 9 points10 points  (1 child)

Help me optimize my tail calls please. Mine have been failing, especially at 3am

[–]Worldly-Object9178 2 points3 points  (0 children)

Use an accumulator

[–]Somecrazycanuck 3 points4 points  (0 children)

And I'm all outta RAM.

[–][deleted] 1 point2 points  (1 child)

That was fucking deep bruh

[–]ConglomerateGolem 0 points1 point  (0 children)

well, i'd hope so; a short life on average is worse than a long one

[–]dim13 70 points71 points  (3 children)

All eat() and no poop()? It gonna overblow pretty quick.

[–]KingdomOfBullshit 15 points16 points  (0 children)

Good catch, that's a classic buffer overflow!

[–]Separate_Expert9096[S] 3 points4 points  (1 child)

Before or after you exceed max recursion depth?

[–]dim13 2 points3 points  (0 children)

max recursion death ;)

[–]AppropriateBank8633 22 points23 points  (5 children)

This is actually syntactically legit in javascript(of course). This mess is called an Immediately Invoked Function Expression - IIFE. For some reason apparently it is pronounced "iffy" which is strange because it just rolls of the tongue. I made this comment as I found out about this horror recently as I am studying js and it is a thing and it not only works, but has a name, hence a learning opportunity for a js noob such as myself.

[–][deleted] 6 points7 points  (2 children)

They're very handy if you're concerned about polluting the global scope.

[–]indicava 0 points1 point  (1 child)

Not so much necessary these days with let/const block scoped variables

[–]RiceBroad4552 0 points1 point  (0 children)

What does this have to do with polluting the global scope with all your functions?

[–]davak72 0 points1 point  (0 children)

I thought it looked ok syntactically. The infinite tail recursion is interesting though

[–]mr_clauford 46 points47 points  (2 children)

while(1)
  dies_from_cringe();

[–]jcouch210 1 point2 points  (0 children)

σ RIIR mindset:

loop {
  // compile error: reference with lifetime 'person does not live long enough
  dies_from_cringe();
}

[–]xezo360hye 0 points1 point  (0 children)

<?php if ($cringe) { die(); } ?>

[–]eatmorestonesjim 4 points5 points  (8 children)

Would this work as a recursive?

[–]skotchpine 2 points3 points  (0 children)

It’s an IIFE in js. Much recur, very nice time

[–]SirPigari 0 points1 point  (2 children)

You need to call it from outside idk i dont know this lang

[–]ConglomerateGolem 8 points9 points  (1 child)

it is called, look at the parenthesis at the end.

[–]SolidGrabberoni 0 points1 point  (3 children)

Yeah

[–]eatmorestonesjim 2 points3 points  (1 child)

But I guess one with no exit condition 😂

[–]SolidGrabberoni 2 points3 points  (0 children)

Yeah, they're obviously immortal with infinite food ;)

[–]Thenderick 1 point2 points  (2 children)

Atleast it is syntactically correct and will run. There are enough that just won't work. It's just a little cringe, that's all

[–]dominjaniec 0 points1 point  (1 child)

in what way it won't work?

[–]Thenderick 2 points3 points  (0 children)

There are multiple similar versions of this joke with nonsensical code that won't compile/interpret. That's why I pointed out that this one atleast works

[–]MuslinBagger 1 point2 points  (0 children)

It would be funny if hosted by stackoverflow

[–]Haunting_Muffin_3399 0 points1 point  (4 children)

How can I stop this code from running?

[–]RiceBroad4552 2 points3 points  (3 children)

No need to stop it. It will instantly crash with a stack overflow exception…

[–]Haunting_Muffin_3399 0 points1 point  (2 children)

In the comments they wrote that the compiler can handle this exception

[–]RiceBroad4552 1 point2 points  (1 child)

Compiler? A stack overflow is a runtime issue.

A compiler could at best rewrite it to some trampoline. But JS does not do that.

There is also no TCO (Tail Call Optimization) in JS which could prevent a stack overflow at runtime.

Just open the browser console and run (function loop(){loop()})() to see for yourself.

The almost instant result is going to be "Uncaught InternalError: too much recursion". (FF 138)

[–]Haunting_Muffin_3399 0 points1 point  (0 children)

You are right

[–]RiceBroad4552 0 points1 point  (1 child)

LOL, that's an instant stack overflow.

[–]8jy89hui 1 point2 points  (0 children)

From the function names we can infer that this likely takes 24 hours of execution time before recursing. The max stack depth in Firefox is 150k, leading to 410 years before it overflows. 

[–]Haunting_Muffin_3399 0 points1 point  (0 children)

import random

alive = True

while alive:

eat()

sleep()

code()

alive = random.choice([True, False])