10
alex111
8y

Fucking recursive algorithms. Does anyone actually use them when programming in real life?

Comments
  • 4
    I used them quite a bit on game development; on apps usually the stuff that need them is already implemented on libraries.
  • 2
    Had to use them once or twice, when implementing unlimited nesting of groups in a communication environment
  • 2
    Use them all the time in personal projects.

    Don't use them at work as everything is safety critical and they are banned.
  • 1
    I used recursion last week to write an algorithm to normalize JSON flat keys or mixed keys to hierarchical key schema.
  • 2
    I get your pain although recursion can be the prettiest way to solve something. Unfortunately, I find the really pretty examples are the ones most likely to blow your stack.

    e.g. Tail recursion is the only kind where in some languages you categorically don't need to worry about this problem because the optimizer will rewrite so that it's not actually recursion. Of course, these are the ones you could rewrite yourself to not recursion so you don't blow your own personal internal callstack.

    The nice uses that save many lines of code are like where each call of the function spawns another 4 of itself going off in different directions. Cute but that callstack is in for pain.
  • 2
    @RubyTuesday - Not true always. Recursion is way more inefficient than iterative loops, especially for larger numbers as recursive algorithms have to store each return value in memory and pass them back to the parent function.
  • 0
    Depends. But yea you use them.
  • 0
    function sayNo() {
    echo "<div class="alert">No!</div>";
    sayNo ();
    }
  • 0
    @nottoobright Not always true. Some languages optimize them into loops.
  • 2
    I use a lot of recursive tree traversals for my current project. If you do functional programming you automatically use more recursion than loops, as well.
  • 1
    I am writing a recursive decent parser that needs recursion

    And the language has infinite recursion? Not just in tail call position
Add Comment