3 ms·
I'm guessing that recursion isn't used much in whatever work you do, but it's very helpful for things like parsers, compiler passes, etc. Basically anything th
by CoastalCoder 4y ago
I'm guessing that recursion isn't used much in whatever work you do, but it's very helpful for things like parsers, compiler passes, etc. Basically anything that has to walk to tree or directed graph, and where you need to build up context based on the traversal path from the starting point to the node you're currently handling.
Obviously in a non-functional language, you can do these things without recursion by using your own stack rather than the runtime function-call stack. But sometimes it's nice to have the stack provided for you. That also plays well with C++ runtime exception propagation.
- mxz3000 4y agoIn production code, you'd generally avoid recursion to avoid stack overflows. Given in most languages you can't enforce tail call optimisation, it's risky to use unbounded recursion.
- CoastalCoder 4y agoI suspect this guideline varies a lot by industry or by target hardware. The last time I worked on a project with that rule was about 23 years ago, and that was on a 32-bit system.