2 ms·
> Avoid recursion if possible to keep execution bounded and predictable, preventing stack overflows and uncontrolled resource use. In languages with TCO (e.g.
by andsoitis 1y ago
> 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.
- rerdavies 1y agoPresumably why it says "Avoid recursion if possible".