TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

1 pointsby pizzaparty2over 5 years ago
I'm specifically interested in C# and JavaScript if you require that distinction.

1 comment

zadlerover 5 years ago
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.