Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 112357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:31:55+00:00 2026-05-11T02:31:55+00:00

35 lines, 55 lines, 100 lines, 300 lines? When you should start to break

  • 0

35 lines, 55 lines, 100 lines, 300 lines? When you should start to break it apart? I’m asking because I have a function with 60 lines (including comments) and was thinking about breaking it apart.

long_function(){ ... } 

into:

small_function_1(){...} small_function_2(){...} small_function_3(){...} 

The functions are not going to be used outside of the long_function, making smaller functions means more function calls, etc.

When would you break apart a function into smaller ones? Why?

  1. Methods should do only one logical thing (think about functionality)
  2. You should be able to explain the method in a single sentence
  3. It should fit into the height of your display
  4. Avoid unnecessary overhead (comments that point out the obvious…)
  5. Unit testing is easier for small logical functions
  6. Check if part of the function can be reused by other classes or methods
  7. Avoid excessive inter-class coupling
  8. Avoid deeply nested control structures

Thanks everyone for the answers, edit the list and vote for the correct answer I’ll choose that one 😉

I am refactoring now with those ideas in mind 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:31:55+00:00Added an answer on May 11, 2026 at 2:31 am

    There aren’t any real hard or fast rule for it. I generally like my methods to just "do one thing". So if it’s grabbing data, then doing something with that data, then writing it to disk then I’d split out the grabbing and writing into separate methods so my "main" method just contains that "doing something".

    That "doing something" could still be quite a few lines though, so I’m not sure if the "number of lines" metric is the right one to use 🙂

    Edit: This is a single line of code I mailed around work last week (to prove a point.. it’s definitely not something I make a habit of :)) – I certainly wouldn’t want 50-60 of these bad boys in my method 😀

    return level4 != null ? GetResources().Where(r => (r.Level2 == (int)level2) && (r.Level3 == (int)level3) && (r.Level4 == (int)level4)).ToList() : level3 != null ? GetResources().Where(r => (r.Level2 == (int)level2) && (r.Level3 == (int)level3)).ToList() : level2 != null ? GetResources().Where(r => (r.Level2 == (int)level2)).ToList() : GetAllResourceList(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several lines of integers in a file E.g 100 20 300 20
I have at least 100 xml files each about 300 MB with email messages
Let's say I have a text file that is 100 lines long. I want
We have a very complex Oracle package here (over 4,100 lines of code) that's
I have the following two lines of code: var BadResult = (100).ToString(B, new CustomFormatter
If this html code is as long as 300 lines. You have to write
Say I have an array of arrays in Ruby, [[100,300], [400,500]] that I'm building
I am working on relatively small (100-300 lines) Javascript files in Eclipse and periodically
I have a file which contains lines of data like below 300,,,292,15.4,0,04/16/12 20:10:39 200,,,292,15.4,0,04/16/12
Each of my 10-15 pages has 100-200 lines of js inside $(document).ready() Would it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.