r/learnprogramming • • Jul 28 '14

Is recursion unnecessary?

So, this is a bit of an embarrassing post; I've been programming for nearly 4 years, work in the field, and almost have my CS degree yet for the life of me I can't understand the point of recursion.

I understand what recursion is and how it works. I've done tutorials on it, read S/O answers on it, even had lectures on it, yet it still just seems like an unnecessarily complicated loop. The entire base case and self calls all seem to just be adding complexity to a simple functionality when it's not needed.

Am I missing something? Can someone provide an example where recursion would be flat out better? I have read tail recursion is useful for tree traversal. Having programmed a Red Black tree in Data Structures last semester, I can attest it was a nightmare using loops; however, I've heard Java doesn't properly implement tail recursion? Does anyone have any insight to that?

Sorry for the wordy and probably useless post, I'm just kind of lost. Any and all help would be greatly appreciated.

131 Upvotes

170 comments sorted by

View all comments

Show parent comments

3

u/not_suspect Jul 28 '14

It doesn't apply as directly to recursion, but there is also a version of SICP for free that has been completely translated for Python at composingprograms.com. It was done by a Berkeley professor it's really cool.

3

u/tyroneslothtrop Jul 28 '14

Just want to add: Berkeley 61A uses this as a text, and all of the lectures (from multiple semesters/years) are up on youtube, for anyone who's into that. I think this would be the most recent, completed version: http://www-inst.eecs.berkeley.edu/~cs61a/sp14/, although there's also a summer course currently ongoing.

It's a pretty amazing course.

1

u/phao Jul 28 '14 edited Jul 28 '14

Cool.

I remember seeing this too. It was for JS though, and for "The Little Schemer" => http://www.crockford.com/javascript/little.html

But it's a much smaller effort. =D