4 ms·
>Given that any recursive function can be written using a while loop with O(1) memory bounds, recursion seems quite a poor choice for all practical purposes. I
by vph 15y ago
>Given that any recursive function can be written using a while loop with O(1) memory bounds, recursion seems quite a poor choice for all practical purposes.
It is very unfortunate that many programmers (including Guildo, circa 2009) think this way. Guildo in particular, when he talked about recursion, his state of mind is about "cons" and "tail" of Scheme.
On the other hand, it is undeniable that algorithmic thinking and problem solving skills are critical to being a good programmer. And as of today those who are trained in the tradition of the Computer Science discipline are equipped with an array of algorithmic strategies all based on recursion. Techniques such as divide and conquer, dynamic programming and much more are all based on the idea of solving a problem in terms of itself, i.e. recursion.
When a programming language eschew recursive strategies, it inadvertently wastes precious skills that are taught to programmers.
Recursions are hard, but they are very powerful, when used properly. There are many problems that can be solved easily and faster with recursion, and you can't simply convert them to loops.
- baddox 15y agoBased on a recent talk I attended, I believe that Guido admits that it's purely a matter of opinion, but he always has to "unroll" the recursive in his head to be able to figure out what recursive code does, so he concludes that it might as well be written the way that he thinks. I agree with that last part, but I can't imagine thinking of every algorithm iteratively. Binary search, merge sort, and pretty much any tree algorithm are examples of algorithms that (to me) are much less natural to thing of iteratively.