23

how in the fuck do people visualize recursion

Comments
  • 3
    I imagine a stack with things pushing and popping on it
  • 1
    How do people visualize? xD
  • 17
    Source: fb/thenewboston
  • 0
    A while loop is flat recursion.
    Recursion is a pseudo lambda.
  • 9
    I 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.
  • 6
    Use LSD, and do some Haskell tutorials. Haskell has no loops, only recursion.
  • 3
    Inject haskell directly into your bloodstream
  • 0
    Inception, maybe... To be honest though I've been playing with functional programming for a while now that I stopped needing to visualise it.
  • 0
    Fractals
  • 4
    Visualize recursion by visualizing recursion by visualizing recursion by visualizing recursion by....
  • 4
    Weed. Wont help you visualize it but will help you forget about.. Wait what was i talking about
  • 4
    Here's Something I did today to trace my 5 line Recursive code:
  • 0
    Lol you are my hero @Cybersapien
  • 0
    Tail 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.
  • 2
    Two mirrors one in front of you and one in your back...
  • 1
    @dontPanic I clicked on this thread specifically because I wanted somebody to have posted that comic.
  • 0
    Imagine a painting in which there is another painting in which there is another painting in which there is another painting in which....
  • 0
    Pickup a pencil and paper. Draw circles untill they end you.
  • 1
    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).
  • 0
    Thinking of it as a stack is good for written verification, but shit for in your head, stack blows up way too fast.
  • 0
    I always think of filming a screen showing the live feed from what I’m filming.

    ..bad explanation, but you get what I mean.
  • 0
    All suggestions about mirrors and paintings within paintings are not recursion, but back coupling.
  • 0
  • 0
    This rant summarizes recursion pretty good:

    https://devrant.io/rants/674169/
  • 1
    when a greek conga starts, the recursion itself is shown
  • 0
    @lihram recursion leads into darkness.
  • 0
    @lihram thats terrifying
Add Comment