Skip to content
DevMeme
3319 of 7590
Bugs Post #3643 · source on Telegram

The Audible Terror of a Missing Base Case in Recursion

Description

A meme featuring the character Private, a wide-eyed penguin from the 'Madagascar' franchise, looking alarmed. A semi-transparent, ghostly image of the same penguin with a thousand-yard stare is superimposed, creating a sense of panic and dawning horror. The text at the top reads: 'You've been working on a recursion and your laptop fan gets noisier every second'. This meme humorously captures a specific moment of dread familiar to developers. The joke is that an increasingly loud laptop fan is the primary physical indicator that a recursive function is out of control, likely due to a missing or incorrect base case. This leads to an infinite loop, consuming massive CPU resources, heating the processor, and ultimately culminating in a stack overflow error. The penguin's terrified expression perfectly mirrors the programmer's realization that they have created a runaway process that is about to crash their application or system

Comments

24
Anonymous ★ Top Pick My laptop fan is my most reliable unit test for recursion. If it sounds like a jet engine taking off, the test failed
  1. Anonymous ★ Top Pick

    My laptop fan is my most reliable unit test for recursion. If it sounds like a jet engine taking off, the test failed

  2. Anonymous

    Pro tip: every time you forget the base case, Big-O silently upgrades to O(fan_speed^n)

  3. Anonymous

    The only thing growing faster than your call stack is your electricity bill - and both are about to hit their hard limits. At least your laptop doubles as a space heater during those long debugging sessions where you forgot the base case

  4. Anonymous

    The real tragedy isn't the missing base case - it's realizing you've been computing fibonacci(45) the naive way while your MacBook Pro transforms into a $3000 space heater. At least the thermal paste is getting a proper stress test, and you're finally understanding why that Staff Engineer kept muttering about 'tail recursion' and 'trampolining' during code review

  5. Anonymous

    When the only tail-call optimization on your machine is the fan curve, you forgot the base case

  6. Anonymous

    Pro tip: if the thermal governor hits its SLO before your recursion hits a base case, you’re benchmarking a space heater, not an algorithm

  7. Anonymous

    Base case? Nah, let's see how deep the stack goes before the fan drowns out your standup

  8. @Dobreposhka 4y

    go slip

  9. @dmytro_kp 4y

    exactly

  10. @karim_mahyari 4y

    It's too bitter for me, I can't joke about it

  11. @anysound 4y

    Btw, can someone who knows this stuff explain me how good modern OSs are at detecting unlimited recursion (rapidly growing stack to be more precise) and killing the process before it severely fucks the system? Because the other day I launched a co-worker's code with infinite recursion in it and I'm pretty sure it took a good portion of my RAM and everything started to lag, but I thought that there must be some limits to prevent that. Or is it possible that such a process will be able to eventually eat all RAM, all free disk space and only then will the system crash? 🤔 Need OS nerds :)

    1. Deleted Account 4y

      ye, you get like 4M of stack space, if there are threads then that's all, else i think you can go just abit more, and that's 'bout it, the process will die of segfault

      1. Deleted Account 4y

        there is a funnier case when the recursion is tco'd away, so it can potentially run forever

      2. Deleted Account 4y

        obtw. why not more? the answer is that, thae stack, unlike the heap, has to be contigious, and it also can't grow over where the heap is too, so you can't get like alot of stack

        1. Deleted Account 4y

          oh, and also, you can't even move the stack, bc that'll instantly invalidate all the refs to stack-allocated objects

    2. @chekoopa 4y

      Sometimes OS doesn't detect that at all, but kills the bloat with OOM, resulting maybe a few seconds of lag.

      1. Deleted Account 4y

        so this only occurs with heap memory, not stack

    3. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

      Well in ios an app cant take more than 50% of all ram. On desktop OSes like windows the app needs to handle when there is no memory anymore normally the app tries to remove unimportant resources from ram or if thats not enough it will exit if the app is properly made. If the app is made like crap then the CPUs interrupt will trigger for stack overflow if that happens before all the ram is eaten up. But normally that would cause the kernel to kill the process and clean the stack.

      1. Deleted Account 4y

        How does a kernel see processes and how much resources they are using

        1. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

          Uhh thats not explainable in a few minutes... PM me and I will write you later how all this shit works

          1. Deleted Account 4y

            Okkayy

            1. Deleted Account 4y

              I can only send msgs to mutual contacts

    4. @dugeru42 4y

      In python normally there is limit fo recursion depth But i was able to overcome that, eat 16gb of ram, 42gb of swap and hard freeze the system

  12. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

    If I do something very complex with a lot of data I open a seperate asynchronous window and draw a deepness graph. That gives me a visual sense of how it enters and leaves recursive functions

Use J and K for navigation