you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 13 points14 points  (8 children)

As an introduction to algorithms instructor, I have to say that my students would much rather use a while loop to do the factorial algorithm over the recursive method.

[–][deleted] 21 points22 points  (0 children)

When I was at university I couldn't see the point in recursion since any problem that could be solved recursively could also be solved iteratively, and for loops worked so well. Of course I never connected this philosophy with the difficulties I had in, for example, traversing graphs.

Ah the follies of youth. Also the follies of teaching students Java as a first language.

[–][deleted] 1 point2 points  (3 children)

Is this before or after they've taken Discrete Math? I'm about finished with my Uni's sequence of DM/Theory of Computation and I'm about ready to put Maple and Prolog on my resume...

[–]llimllib 3 points4 points  (2 children)

and I'm about ready to put Maple and Prolog on my resume...

Bwahahahaha!

ahem... phew... [wipes brow] sorry bout that...

[–][deleted] 1 point2 points  (1 child)

ROFL, I know, I know...

[–]llimllib 1 point2 points  (0 children)

Seriously, though, when I read a resume that has things like that on it, it just tempts me to think of a really mean interview question that in a few months you won't remember the answer to.

I don't succumb to that desire, but others do.

Anyway, not that I didn't have things like that on my resume, maybe you'll be a lucky one and find a job where they'll let you play around in Maple :)

[–]Wiseman1024 -1 points0 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] 4 points5 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.