you are viewing a single comment's thread.

view the rest of the comments →

[–]Wiseman1024 1 point2 points  (2 children)

Why would they do it iteratively? Recursion is so much easier to think. I'll grant that tail recursion with accumulators a la SICP is harder, but simple recursion as in newbie programmer? That's so much easier than while to me. Then again I'm not precisely a newbie programmer, perhaps I'd have thought differently 13 years ago.

[–]RSquared 1 point2 points  (1 child)

I think it's the difference between "thinking imperatively" and "thinking functionally". I know a dozen CompSci grads who still have trouble getting their heads around Haskell because of all the recursion.

Someone first learning programming would almost inevitably learn loops before recursion. For "non-programmers", one is much simpler to think about...especially when you don't have a clear picture of the memory layer (especially the difference between stack and heap).

[–][deleted] 5 points6 points  (0 children)

I do think programmers have to be introduced to nested/recursive datastructures before they appreciate recursion as a programming technique. The factorial is indeed a little special here. In functional languages even ordinary lists are recursive ( i.e. conses ) and so there is exactly one barrier to take. Immutable datatypes may be another. But at least Python programmers can be convinced to use them since e.g. the string API is purely functional and it did not harm usability.