Which programming concept do people usually find harder: loops or recursion?

Quora Feeds

Active Member
Shriram Krishnamurthi

I disagree with just about every answer written here. There are two reasons why people might answer "recursion", and each one needs more discussion.

But before I go on: I get many comments from people who assume I am somehow in the anti-recursion camp. On the contrary, I have been teaching recursion for over 20 years, and think most of the confusion about it is entirely artificial. To understand how I teach it, see Shriram Krishnamurthi's answer to How does professor Shriram Krishnamurthi teach the concept of recursion?.

Back to my answer to this question:
  1. Our basic pedagogy of recursion is broken. Were you taught fibonacci or factorial first? If so, you were taught the two worst examples of recursion one can imagine—both should be banned from CS education. In contrast, our book How to Design Programs teaches you to begin from structural recursion. Why? Because structural recursion follows from the structure of the data. It is amazingly natural. Only after you've mastered structural recursion do we teach generative recursion, which requires you to invent recursive structures.
  2. This problem of pedagogy is compounded by two things instructors do:
    1. Teach loops before recursion (thanks for reminding me, Jesse Tov). Therefore, one is made to look more basic than the other.
    2. Push recursion to a second course, as an “advanced” concept. Then teach it with a great deal of Sturm und Drang.
    As a result, students internalize that recursion is this difficult topic, and then pass that on genetically to their students, to textbooks, to blogs, and everything else. (I had the good fortune of not being taught recursion formally, so I never got to learn that it was “difficult”.)
  3. Unlike loops, recursion expands. You can recur over linear data, but you can also recur over non-linear data. You can recur structurally or generatively. With enough recursion you can even generate new control structures such as state machines (e.g., Automata via Macros). You can't do any of this with loops.
So, to summarize: (1) conventional recursion education is awful; (2) recursion lets you do many more things. Therefore, it is a much more powerful feature and as such must be taught through a graduated introduction. Unfortunately, most people have been taught recursion poorly, and then teach it to others poorly, leading to an endless, uh, loop of ignorance. See how to teach it well: Shriram Krishnamurthi's answer to How does professor Shriram Krishnamurthi teach the concept of recursion?.

See Questions On Quora

Continue reading...
 
Top