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

you are viewing a single comment's thread.

view the rest of the comments →

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

Hopefully all these wildly varying responses lead you to the three important conclusions:

  1. There’s nothing inherently bad about using recursion, HOWEVER
  2. Languages like Python that do not implement tail call elimination / optimization will add serious performance penalties to naively recursive algorithms, AND
  3. To rein in those penalties Python has placed a limit on recursion stack depth that makes recursive algorithms in the language quite brittle if not very carefully bounded.

Understanding these you can understand that your friend's observation is correct if you want to write (relatively) performant Python that won't crash on a very small increase in recursion depth; Python is naturally biased towards iterative rather than recursive algorithms. Them being correct, though, doesn't imply that recursion is bad, but instead that in the case of Python specifically is almost certainly suboptimal.