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?
- Methods should do only one logical thing (think about functionality)
- You should be able to explain the method in a single sentence
- It should fit into the height of your display
- Avoid unnecessary overhead (comments that point out the obvious...)
- Unit testing is easier for small logical functions
- Check if part of the function can be reused by other classes or methods
- Avoid excessive inter-class coupling
- 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 :)