
You Don't Hate Recursion. You Were Taught It Wrong.
https://www.youtube.com/watch?v=_h-pzH4Hy0E Three lines of code drew a Sierpinski triangle. A function that draws a triangle, then calls itself three times — each time smaller, each time nested inside the last. That's not a loop. That's recursion. And every tutorial explains it wrong. The Real Mental Model They tell you recursion is "a function calling itself." Technically true. Completely useless. Here's what actually happens. When factorial(3) runs, the machine doesn't just re-enter the function. It builds an entirely new world — a private copy with its own variables, its own state, sealed off from the original. That copy builds another copy. And another. Until you hit the floor. The code looks like one function. At runtime, four separate worlds exist simultaneously — stacked in memory, each frozen at a different moment, each holding a different value of n . The Call Stack: Dreams Inside Dreams Think of the call stack like dream levels in Inception. Every function call pushes a new f
Continue reading on Dev.to
Opens in a new tab



