3 ms·
> Otherwise you'd have to explicitly code a loop where you would much rather use recursion. I find it much easier to reason about loops than to reason about re
by codetrotter 4y ago
> Otherwise you'd have to explicitly code a loop where you would much rather use recursion.
I find it much easier to reason about loops than to reason about recursion. Likewise I find it much easier to write loops than to write recursive functions.
It probably comes down to experience mainly. I spent some time with functional languages, but I have spent far far far more time writing imperative procedural code.
- jacquesm 4y agoEven a simple problem such as the 'Towers of Hanoi' looks to me like a pretty messy solution when done with loops and with recursion it all just falls into place.
- Jensson 4y agoRecursion is great due to the implicit stack. The cases where you don't have an implicit stack, ie where tail call optimization works, are usually easier and much clearer to just do in a loop.