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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: What is the maximum number of lines a function should have?

1 点作者 pizzaparty2超过 5 年前
I'm specifically interested in C# and JavaScript if you require that distinction.

1 comment

zadler超过 5 年前
It doesn’t make sense to think about a maximum number of lines.<p>There may be a complex function of many variables which is not simplified by splitting into multiple functions.<p>Most often though, the code in a function has several logical parts which have their own temporary variables and are good candidates for splitting into separate functions.<p>Generally it makes sense to split code up so that it can be encapsulated at different levels. For example if you have a validation routine for a record, it may make sense to have different functions to test different properties, so that you can see which validations are being performed at a high level and then zoom in when you need to.<p>Encapsulation should be done to manage scope of temporary variables, and to make the code easier to read and to test. But there’s no hard and fast rule, really.