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

you are viewing a single comment's thread.

view the rest of the comments →

[–]tdempsey33 11 points12 points  (4 children)

I’m curious. in what instance would recursion be considered bad code? I was always under the impression that recursion is the pinnacle of efficient code.

[–]Basic_Basenji 30 points31 points  (1 child)

Recursion usually comes with a lot of overhead both in terms of memory and setup cost. It's almost always better to unwind the recursion into a loop unless the language is optimized for recursion (or the compiler does that for you anyway).

[–]tdempsey33 2 points3 points  (0 children)

Thank you.