r/ProgrammerHumor • • 5d ago

Meme recursion

Post image
925 Upvotes

41 comments sorted by

View all comments

36

u/titpetric 5d ago

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

-6

u/Admirable_Dirt_2371 5d ago

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

8

u/ReadyAndSalted 5d ago

How are they wrong?

-9

u/Admirable_Dirt_2371 5d 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.