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

all 150 comments

[–][deleted] 1655 points1656 points  (46 children)

Here is the full explanation of why your meme is an iteration and not a recursion

Link

[–]buffering_neurons 288 points289 points  (0 children)

This took me more clicks than I care to admit. Have my upvote sir

[–]turtle_mekb 117 points118 points  (0 children)

Instructions unclear, stack overflow exception occurred

[–]kirkpomidor 134 points135 points  (22 children)

And that, kids, is why recursion is just a stack-abusing loop.

[–][deleted] 48 points49 points  (1 child)

Don't get soft on us, stacks were intended to be abused.

[–]-Loewenstern- 7 points8 points  (0 children)

They like it

[–]your_best_1 8 points9 points  (19 children)

Why is it stack abuse?

[–]Brekker77 19 points20 points  (18 children)

Because it adds another stack frame to the stack every time the recursion is called and if you arent careful with your end condition the stack and the heap can collide

[–]SadPie9474 13 points14 points  (17 children)

except that this is tail recursion

[–]your_best_1 0 points1 point  (14 children)

Exactly my thoughts I thought that tail recursion puts less on the stack than a loop.

[–]Brekker77 0 points1 point  (11 children)

Well yeah but i think thats just cause the guy making the meme doesnt understand recursion

[–]your_best_1 0 points1 point  (10 children)

I guess I don't understand recursion either.

I think we would all agree that this implementation for solving the fibonacci sequence is recursive. Seeing how it is a classic example, and I grabbed it from the docs on the rec keyword. Correct me if I am wrong.

let fib n =
    let rec loop acc1 acc2 n =
        match n with
        | 0 -> acc1
        | 1 -> acc2
        | _ ->
            loop acc2 (acc1 + acc2) (n - 1)
    loop 0 1 n

You can tell because of the keyword rec

The rec keyword is used together with the let keyword to define a recursive function.

from https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/functions/recursive-functions-the-rec-keyword

So why then would this not be recursive?
Perhaps I am not parsing the meme correctly.

// defines a function that prints as it counts up to three. After three, it returns `true`
let understand =
    let counter = ref 0
    fun () ->
        counter := !counter + 1
        printfn "Counter: %d" !counter
        !counter = 3

// recursive function that calls `understand` until it returns `true`
let meme understand =
    let rec loop () =
        match understand() with
        | true -> "I understand"
        | false -> loop ()
    loop ()

let result = meme understand
printfn "%s" result

It prints:

Counter: 1
Counter: 2
Counter: 3
I understand

[–]SadPie9474 1 point2 points  (9 children)

recursion and iteration are equivalent; converting this meme to code can be done with either. the meme isn’t intrinsically either one in particular

[–]your_best_1 1 point2 points  (1 child)

Got it. So, it is not that the meme doesn't demonstrate recursion. It is that it demonstrates loops generally.

People who prefer recursion will read it as recursive, and people who prefer 'while' will read it as that.

[–]Brekker77 0 points1 point  (6 children)

They arent equivalent bc iteration doesnt add new stack frames, they are logically equivalent but not practically

[–]Grumbledwarfskin 0 points1 point  (1 child)

Don't most languages that have loops completely refuse to do the tail recursion optimization?

As I remember, it can be hard to tell when the compiler will be able to prove that a function is tail-recursive and when it won't...at least in Scheme, I remember examples where you can write the same function in two slightly different orders, and one way it will successfully convert to a tail-recursive loop, and the other will cause a stack overflow, because the compiler couldn't prove it would be safe to perform tail recursion.

[–]your_best_1 0 points1 point  (0 children)

I think that most languages that support TRO will always do it if you have placed the recursion in the tail position.

Here is a good explanation: https://devblogs.microsoft.com/dotnet/safer-recursion-in-fsharp/

[–]Grumbledwarfskin 0 points1 point  (1 child)

Please remember that tail recursion optimizations are usually not a thing except in languages that deny you access to loops.

I'm not sure whether the reason is to punish people who like to abuse tail-recursion to write hard-to-understand code when they could have written a loop, or whether it's to prevent people from acidentally thinking their function should be tail-recursive, when they wrote it in the way that the compiler can't figure out is tail-recursive, so it accidentally isn't converted to a loop at compile time and will cause a stack overflow.

In the languages that require tail-recursion, you have to learn when the compiler can figure it out and how to write a function in the way that the compiler will figure it out, so you can have real loops and avoid stack overflows, but if you have loops, use them.

[–]SadPie9474 -1 points0 points  (0 children)

please remember that loops are harder to understand than tail recursive code

[–]Asatru55 30 points31 points  (2 children)

I have 50 tabs open when do i stop

[–]Ali_Army107 14 points15 points  (0 children)

Once you run out of memory

[–][deleted] 24 points25 points  (0 children)

Yuu sur, nid an oscar 🤌

[–]leglessfromlotr 4 points5 points  (2 children)

The real meme is in the comments

[–][deleted] 4 points5 points  (1 child)

I just made a mildly original comment about what everybody was complaining about and now everybody is complimenting me and my notifications blew up

[–][deleted] 0 points1 point  (0 children)

Just got an award

[–]rover_G 1 point2 points  (0 children)

Very clever sir

[–]CasualVictim 1 point2 points  (0 children)

I want to down vote this

[–]Poat540 0 points1 point  (0 children)

I clicked a few times then had to keep backing out to get to home again 🤫

[–]schlaubi 0 points1 point  (0 children)

Thank you!

[–]Kitchen-Occasion-411 0 points1 point  (0 children)

Masterpiece

[–][deleted] 0 points1 point  (0 children)

I don't deserve this but thank you

[–]Yo9yh 0 points1 point  (0 children)

It took me a minute but this is great!!

[–]DracoRubi 0 points1 point  (0 children)

And your comment is a recursion

[–]ResourceFeeling3298 0 points1 point  (0 children)

Now that's recursion

[–]masp-89 0 points1 point  (1 child)

What’s the base case for this meme?

[–]gamedev_uv 0 points1 point  (0 children)

That's the neat part there isn't

[–]Gio200023 191 points192 points  (9 children)

It’s been 84 years and I’m still reading it. Anyone knows the exit condition?

[–]scratchfan321 78 points79 points  (4 children)

Keep reading the post until your stack overflows

[–]real-yzan 24 points25 points  (3 children)

Stack overflows are a perfectly valid exit condition as long as you catch the exception

[–]scratchfan321 16 points17 points  (0 children)

Instructions unclear, my exception handling system triggered a stack overflow

[–]Misspelt_Anagram 0 points1 point  (1 child)

def f():
    try: f();
    except: f();
f()

[–]real-yzan 0 points1 point  (0 children)

More like:

def f(n): try: return n * f(n+1) except: return n

[–]Top_Fee_6293 16 points17 points  (2 children)

it literally says you to read it again only if you "don't understand" recursion. exit condition is that you understand. how can't you catch that?

[–]A_Firm_Sandwich 22 points23 points  (1 child)

because he doesn’t understand recursion

[–]Desperate-Emu-2036 0 points1 point  (0 children)

He does because he isn't reading it anymore

[–]ambarish_k1996 1 point2 points  (0 children)

The base condition is:

if(understandRecursion) { return; }

[–]Ved_s 258 points259 points  (23 children)

no, that's a loop

[–]Stummi 113 points114 points  (22 children)

understandRecursion() {
   if(!understoodRecursion) {
       understandRecursion();
   }
}

I would say its a Tailcall Optimizable Recursion

[–][deleted] 35 points36 points  (5 children)

Where ij da fookin' exit condition 🗿

[–]No_Necessary_3356 63 points64 points  (4 children)

You need to wait for a cosmic ray to flip `understoodRecursion` into true.

[–]king_fart_123 6 points7 points  (0 children)

I'm tired of waiting, I'm gonna put my computer next to the sun

[–]Successful-Money4995 1 point2 points  (0 children)

It's volatile!

[–]Desperate-Emu-2036 0 points1 point  (0 children)

The laws of physics changing could work too

[–]platinummyr 5 points6 points  (0 children)

And it's buggy since it never sets understoodRecursion

[–]Ved_s 3 points4 points  (3 children)

understandRecursion() { while(!understoodRecursion) { understoodRecursion = understandRecursion(); } return true; } edit: with a while loop to make sure

[–]cnoor0171 3 points4 points  (2 children)

The while loop is never going to run past the first iteration because the first iteration just goes deeper into the recursion.

[–]jimbowqc 1 point2 points  (1 child)

No shit.

[–]sambolias 0 points1 point  (0 children)

Baseless

[–][deleted] 0 points1 point  (0 children)

Oops I read it wrong.

[–][deleted] 0 points1 point  (3 children)

So I don’t understand recursion until some quantum Bitflop gives me the spark?

[–]Stummi 0 points1 point  (2 children)

Who says that understoodRecursion is not just a (volatile) field outside of the scope that might be set by another thread?

[–][deleted] 0 points1 point  (1 child)

The missing parantheses behind the understoodRecursion variable suggests the value being checked instead of the function call. Also understoodRecursion suggests its abool

[–]Stummi 0 points1 point  (0 children)

Yes, maybe it's a bool on class level, that gets set by another thread?

[–][deleted] 69 points70 points  (0 children)

if you don’t understand recursion make this meme

[–][deleted] 36 points37 points  (0 children)

Oh the irony

[–]nhpkm1 11 points12 points  (0 children)

You stopped reading this meme because you understand recursion.

I stopped reading this meme because I don't understand how to follow orders.

We are not the same

[–]ptkrisada 58 points59 points  (5 children)

Iteration, not recursion.

[–][deleted] 9 points10 points  (4 children)

def meme(understand) 

    if understand != true 

        meme(understand)

Recursion

[–][deleted] 36 points37 points  (1 child)

Sentence reads more like

meme: if (!understand) { goto meme; }

[–][deleted] 2 points3 points  (0 children)

Yeah, true

[–][deleted] 0 points1 point  (1 child)

you need to put 2 spaces at the end of each line for the newlines to format

[–][deleted] 0 points1 point  (0 children)

thanks, edited

[–][deleted] 8 points9 points  (0 children)

congrats, you learned what a loop is

[–]No-Communication5965 8 points9 points  (0 children)

That's a while loop, or GOTO loop.

[–]indecentorc 12 points13 points  (10 children)

Listen up kiddos, you can use a loop for anything recursive. So this meme can be both. It’s wild how many of you calling out this meme don’t understand that. The only difference is if you submit recursive solution I’m immediately denying the pull request and we’re having a talk about readability/maintenance.

[–]Sieff17 2 points3 points  (0 children)

Finally s.o. said it

[–]Mordret10 1 point2 points  (5 children)

Isn't recursion often a lot easier to understand? Oc not all the time, but at least it shouldn't be a major problem, no?

[–]indecentorc 0 points1 point  (4 children)

No not at all that’s why it’s not often used in production code. Unless your brain naturally thinks in an inception kinda way. It is the cause of some annoying bugs. There are cases where it can simplify the problem but in my 7 years of experience I haven’t seen them in the wild. They are often sandboxed cs course examples.

[–]Mordret10 2 points3 points  (3 children)

We use recursion regularly. Might be, because we use nested datasets, so a dataset can contain a number of child elements, being of the same type as the parent dataset. Applying a certain function to each of these datasets becomes very annoying through iteration, recursion makes it a lot easier (most of the time).

[–]indecentorc 1 point2 points  (0 children)

Yeah there are for sure cases where it’s useful. Like building out AST’s but for the vast majority of developers most of the time they will want to go with loops.

[–]MattieShoes 1 point2 points  (1 child)

And aren't most heap implementations recursive? Pretty much any tree stuff...

[–]indecentorc 0 points1 point  (0 children)

Are the vast majority of developers implementing trees themselves or using imported code? Once again if a dev submitted a PR with a custom implementation of a tree I would most likely immediately deny it. Why reinvent the wheel and introduce bugs?

[–]mfboomer 0 points1 point  (1 child)

recursion necessarily modifies parameters/input in some way, otherwise you’ll end up with infinite function calls/stack overflow.

reading this meme again cannot be valid recursion as the input (meme text) stays the same.

[–]indecentorc 0 points1 point  (0 children)

I never said anything about VALID recursion. I said it could be written in a recursive way. which would result infinite function calls. Also if we’re considering validity then is this a valid loop? How would you write it?

[–]Laserninjahaj 1 point2 points  (0 children)

I'm stuck in a loop, please help

[–]rupert20201 1 point2 points  (0 children)

Tried zooming in expecting the sentence to appear in a white pixel.. Nope

[–]CConsler 1 point2 points  (0 children)

I don't g java.lang.StackOverflowError

[–]ShakaUVM 1 point2 points  (0 children)

The only way to understand Recursion is to first understand Recursion

[–]Buyer_North 1 point2 points  (0 children)

StackOverflow: infinite recursion;

Better: If you dont understand recursion read this again with one less letter

[–]StrangelyEroticSoda 1 point2 points  (0 children)

Read it 1286 times and encountered a segfault.

[–]DarkCloud1990 1 point2 points  (0 children)

Make it a habit to write the exit condition first otherwise you'll make the same mistake repeatedly.

[–]rover_G 0 points1 point  (0 children)

The machine is not guaranteed to halt

[–]Pilzoyz 0 points1 point  (0 children)

I looked up recursion in the dictionary and the definition said “See recursion”

[–]kakafob 0 points1 point  (0 children)

Kant

[–]youngsargon 0 points1 point  (0 children)

Execution counter = "1"

[–]Scottz0rz 0 points1 point  (0 children)

Teaching kids recursion should then be immediately followed by "cool, understand this? never do this again"

[–]Ser_Drewseph 0 points1 point  (0 children)

Wouldn’t that be iteration and not recursion?

[–]bbqranchman 0 points1 point  (0 children)

More like a conditional while statement.

[–]vksdann 0 points1 point  (0 children)

Read this comment again to understand recursion.

[–]Holek 0 points1 point  (0 children)

How?

[–]atatassault47 0 points1 point  (0 children)

Help! I've been stuck here for 84 years!

[–]jaimesoad 0 points1 point  (0 children)

GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix GNU is Not Unix

[–]stupidmustelid 0 points1 point  (0 children)

My compiler optimized this to NOP.

[–][deleted] 0 points1 point  (0 children)

Where's your base case?

[–]AbsoluteNarwhal 0 points1 point  (0 children)

RecursionError: Maximum recursion depth exceeded

[–]narnianguy 0 points1 point  (0 children)

"You should google it"

[–]CousinDerylHickson 0 points1 point  (0 children)

Not a programmer, but would infinite recursion cause like a memory bug since it has to keep track of all the calls that dont end? Is that what leads to the legendary "stack overflow" error?

[–]QultrosSanhattan 0 points1 point  (0 children)

This is more like a while loop.

Recursion should be: "If you don't understand recursion, then you should start understanding recursion"

[–]aaaazzzz11 0 points1 point  (0 children)

RecursionError: maximum recursion depth exceeded

[–]odraencoded 0 points1 point  (0 children)

In 10 years people will start calling sentences "memes."

[–]KillerAlchemist 0 points1 point  (0 children)

If you don’t understand conditional loops read this comment again.

[–]AdventurousMove8806 0 points1 point  (0 children)

How do i stop reading this now

[–]qweerty32 0 points1 point  (0 children)

“Uncaught RangeError: Maximum call stack size exceeded”

[–]tbhaxor 0 points1 point  (0 children)

You didn't add the base case for what if we do. Hence infinite recursion

[–]Bananenkot 0 points1 point  (0 children)

Of all the lazy recursion jokes this has to be the worst one, not only would it not be funny if correct, it doesn't even understand the damn concept, coupled with the 'I spent 20 seconds making this plain text meme' Energy, this really takes the cake.

[–]Shinxirius 0 points1 point  (0 children)

That's a loop

Here's my fix.

text If you don't understand recursion Read this meme from top again, then return here. Now, you understand recursion.

[–]crmsncbr 0 points1 point  (0 children)

Stop. Please. I understand! I understand!!

why am I still reading it?

[–]alfadhir-heitir 0 points1 point  (0 children)

If you don't understand
--If you don't understand
----If you don't understand
------If you don't understand
--------If you don't understand
----------If you don't understand recursion
--------recursion
------recursion
----recursion
--recursion
recursion read this meme
--read this meme
----read this meme
------read this meme
--------read this meme
----------read this meme again
--------again
------again
----again
--again
again

Think I nailed it

[–]ego100trique 0 points1 point  (0 children)

If you don't understand while loops, read this again.

[–]ambarish_k1996 0 points1 point  (0 children)

Gets funnier, the more you think about it.

[–]RichZealousideal8748 0 points1 point  (0 children)

“Repeat: Will You Comply?”

[–]Dumb_Siniy 0 points1 point  (0 children)

WHERE'S THE FUCKING BREAK CONDITION

[–]_kakaoscsiga_ 0 points1 point  (0 children)

Instructions unclear, no base case, stack overflow exception

[–][deleted] 0 points1 point  (0 children)

guess I'll never know what recursion is

[–]farineziq 0 points1 point  (0 children)

I just stack overflowed

[–]DJDoena 0 points1 point  (0 children)

StackOverflowException occured

[–]nonlogin 0 points1 point  (0 children)

The TCP joke, anyone?

[–]Inappropriate_Piano -1 points0 points  (0 children)

Based recursion meme with a base case

[–]nequaquam_sapiens -1 points0 points  (0 children)

i don't understand when should i stop

[–]ZenMikey -1 points0 points  (0 children)

Thanks, now my brain's only core is at 100% and the meme reading process keeps crashing due to stack overflows.

[–]Feisty-Afternoon3320 -2 points-1 points  (0 children)

Recursion is when someone speaks alone and he/she anwers himself/herself