20
donuts
7y

I used to prefer, think, and code in loops rather recursion.

Now though somehow it's the other way around...

And I have to assure myself why a piece of code I wrote won't cause a Stack overflow... and that if I really had to I could convert it back to a loop.

Haven't done it though for a awhile tho...

Comments
  • 2
    Recursion 💜
  • 9
    Fun fact: NASA coding standards forbid using recursion, for any reason, ever. Not saying recursion is good or bad, I just read that the other day and thought it was interesting
  • 4
    @LuckierDodge
    It makes sense. Typically, recursion:
    • Is harder to code
    • Is harder to debug
    • Has increased resource usage

    Depends on the specific use case and implementation, ofc.
  • 1
    @Root and more likely to crash if the base case is not clear... or not reachable
  • 1
    I avoid recursion in production
  • 1
    With loops I take at least 5 minutes to be sure that my code won't get an ArrayOutOfBoundsException especially when my loop condition uses someVar - 1 or someVar.
  • 2
    @Root Also, if your algorithm has branches, you need to make sure you don't pass twice in some branches. Fibonacci with recursion is a classic example of this.
Add Comment