r/ProgrammerHumor • • 8d ago

Meme recursion

Post image
957 Upvotes

41 comments sorted by

View all comments

40

u/titpetric 8d ago

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

13

u/Agent_Choocho 8d ago

Trees would like to have a word

4

u/Wonderful-Habit-139 8d ago

Can they not?

2

u/awesome-alpaca-ace 6d ago

If you don't know how 

-7

u/[deleted] 8d ago

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

9

u/ReadyAndSalted 8d ago

How are they wrong?

-10

u/[deleted] 8d 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.

12

u/Wonderful-Habit-139 8d 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.

4

u/RedAndBlack1832 7d ago

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

3

u/titpetric 8d ago

What do you mean?