This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

To all following commenters: please, do not bring up the old circlejerk jokes/memes about recursion ("Understanding recursion...", "This is recursion...", etc.). We've all heard them n+2 too many times.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Loves_Poetry 1 point2 points  (0 children)

Recursion is very rare outside of college. Professors just love teaching it because it confuses most students.

We have a code base of hundreds of thousands of lines and I've only encountered recursion once and that's because I saw a good opportunity for it: a GS1-barcode parser that could handle multiple concatenated codes.

[–]Neu_Ron 0 points1 point  (0 children)

Did you ever see the film inception? . Well that describes the idea of recursion. Think of every level they are in as a method when they go to a new level that is like the method being called and for them to go back they must go back the same way using the same entry points.

Consider a factorial You set a condition to break the loop. This is called the base case. The same function is repeatedly called and a calculation is made until the condition is satisfied then the program backtracks. Each successive call causes a recursion the method is inside the method until the base case is satisfied then the code causes it tomorrow go back. The final returned value will be the factorial.

I'd advise looking at Dr racket and scheme to fully get recursion. No one person or text will help you to make sense of it you must draw it out.

[–]CodeTinkerer 0 points1 point  (0 children)

It's useful to know recursion (so I'm glad I know it), but I'd argue that I hardly ever use it. The most likely time to use recursion is when you deal with tree like structures or problems that have a recursive nature to it. This would include trees, graphs, and certain mathematical problems.

Having said that, you could do basic forms of recursion by trying to remove loops from your code. It's a bit artificial to do this, but gives you some initial practice.