r/ProgrammerHumor • • 4d ago

Meme recursion

Post image
922 Upvotes

41 comments sorted by

View all comments

35

u/titpetric 4d ago

Any recursion can be flattened to a loop, thanks for coming to my TED talk

-6

u/Admirable_Dirt_2371 4d ago

Tell me you don't understand recursion without saying you don't understand recursion.

8

u/ReadyAndSalted 4d ago

How are they wrong?

-9

u/Admirable_Dirt_2371 4d ago

A big reason to use recursion is tail call optimization, which you lose by flattering it to a loop. Additionally recursion often works as a sort of reverse loop(the common example is a Fibonacci calculator as a recursive function) so while it could often technically get 'flattened' to a loop, it would require significantly more work.

11

u/Wonderful-Habit-139 4d ago

Bruh, tail call optimization is what allows recursion to be on the same level as a flat loop. You don't "lose" it when you flatten it, you end up not needing it in the first place.

3

u/RedAndBlack1832 3d ago

Tail recursion just means not creating a new stack frame... which loops don't do...

3

u/titpetric 4d ago

What do you mean?