TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How prevalent is the use of recursion in production level software?

4 点作者 curious16超过 2 年前
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?

5 条评论

duped超过 2 年前
It&#x27;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&#x27;s still using recursion, it&#x27;s just explicit.<p>It is also used extensively in parsers and compilers. There&#x27;s also recursive data structures, which are also extremely common.
tus666超过 2 年前
Quite regularly in Python, despite the stack limitation.<p>Why? It&#x27;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.
josephcsible超过 2 年前
In Haskell, it&#x27;s effectively mandatory in all but the simplest programs, as there&#x27;s no other way to implement any form of looping. It&#x27;s usually done via higher-order functions like foldr rather than explicitly, though, which mitigates almost all of the danger.
jamesfinlayson超过 2 年前
I think I&#x27;ve seen it used once or twice in my career so not common.
kstenerud超过 2 年前
Often, if the language guides people towards recursion.<p>Almost never if it doesn&#x27;t.<p>You need strong language support, otherwise you&#x27;ll be in for a world of hurt.