logoalt Hacker News

andsoitistoday at 8:13 AM1 replyview on HN

> Avoid recursion if possible to keep execution bounded and predictable, preventing stack overflows and uncontrolled resource use.

In languages with TCO (e.g. Haskell, Scheme, OCaml, etc.) the compiler can rewrite to a loop.

Some algorithms are conceptually recursive and even though you can rewrite them, the iterative version would be unreadable: backtracking solvers, parsing trees, quicksort partition & subprblems, divide-and-conquer, tree manipulation, compilers, etc.


Replies

rerdaviestoday at 9:16 AM

Presumably why it says "Avoid recursion if possible".