Recursion is often portrayed as something that can crash your system if not tamed properly. But recursion is really useful to deal with naturally recursively structured data like trees and all.<p>So, is recursion widespread in real software that is used by a lot of people or is it avoided whenever possible?<p>Is it entirely dependent on the language used?
It's extremely common.<p>Recursion only blows up if your PL has fixed size stacks and no tail call elimination. There are plenty of languages which support both, and recursion is safe.<p>Particularly with growable stacks, the alternative to recursion is to use something that has equivalent runtime characteristics as a growable stack (even making one explicitly). That's still using recursion, it's just explicit.<p>It is also used extensively in parsers and compilers. There's also recursive data structures, which are also extremely common.
Quite regularly in Python, despite the stack limitation.<p>Why? It's sometimes the only elegant way to walk over small tree-like data structures, the depth of which you can be safely assured will never approach Python inbuilt limit (and if they did, it would always be a data error that should fail anyways).<p>I do wish Python had Perl-style tail-recursion though.
In Haskell, it's effectively mandatory in all but the simplest programs, as there's no other way to implement any form of looping. It's usually done via higher-order functions like foldr rather than explicitly, though, which mitigates almost all of the danger.
Often, if the language guides people towards recursion.<p>Almost never if it doesn't.<p>You need strong language support, otherwise you'll be in for a world of hurt.