Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lotd79227yI imagine bugs bunny jumping into a hole that turns out to be a black hole, causing a temporal anomaly which renders the space / time continuum to repeat itself,
Until he eventually hits singularity and his mass goes full schrödinger. -
nmunro31907yInception, maybe... To be honest though I've been playing with functional programming for a while now that I stopped needing to visualise it.
-
Visualize recursion by visualizing recursion by visualizing recursion by visualizing recursion by....
-
boom5217yWeed. Wont help you visualize it but will help you forget about.. Wait what was i talking about
-
jxsl13807yTail recursion can be visualized easily, because it can be converted to a loop easily.
The real recursion can only be visualized with lots of training. One mental model I learned was to vusualize it as a stack full of copies of your e.g. function.
You start with taking one copy of code, walk through the code and note all local variables in that copy of your code. In order to know the values before and after the recursive call of itself. Them when you get to your recursive call, you take another copy of that function and push it on your stack and start anew. When you hit a return statement, you take the returned value, and pop the peek copy from your stack, continue where you left off on the copy below and so in. Global variables should be noted on a completely different sheet of paper, because, you know, global. -
@dontPanic I clicked on this thread specifically because I wanted somebody to have posted that comic.
-
Imagine a painting in which there is another painting in which there is another painting in which there is another painting in which....
-
To do recursion properly you only have to really think of two things. First what's the stop condition, code that first, it should be a return at the top of function. And then think of how to transition from state N to N+1. That state transition is the body of the function. Now you can just visualize that it's a loop where the state transition occurs over and over. Another helpful tip is that parameters act like variables, if you need store store extra info in a recursive call you can pass it to the next call via a parameter (or return value).
-
Thinking of it as a stack is good for written verification, but shit for in your head, stack blows up way too fast.
-
grosten14507yI always think of filming a screen showing the live feed from what I’m filming.
..bad explanation, but you get what I mean. -
jxsl13807yAll suggestions about mirrors and paintings within paintings are not recursion, but back coupling.
Related Rants
how in the fuck do people visualize recursion
undefined
recursion
c++