• lysdexic@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    arrow-down
    1
    ·
    9 months ago

    As a rule of thumb, I would say that recursion should never be used in place of a for loop.

    If you don’t know what you’re doing with a recursive function then you risk pushing stuff to your call stack proportionally to the number of items you want to iterate over.

    If your collection and/or the size of the stuff you’re pushing to the stack is large enough, your app will crash.

    If you know enough to avoid growing the call stack then you know enough to not rely on third parties to figure out if you need an iteration of recursion.