How can I find out that whether a method is considered a long method or not. Because, it may possibly contain 3 lines of code or it may contain 300 lines of code. If it contains 3 lines of code then it is not a long method, but if it contains 300 lines of code then definitely it is a long method. My question is how can someone find out that whether it is a long method or not. Is there any algorithm?
Asked
Active
Viewed 136 times
2 Answers
0
Uncle Bob suggests a method should have no more than 4 lines. Only in rare cases you could disregard this rule.

Sergii Shevchyk
- 38,716
- 12
- 50
- 61
-
Uncle Keith suggests that this is too small a number. The vast majority of Java methods in the world (excepting accessors) exceeds this number. This includes most methods in textbooks and in production code. – kc2001 Dec 14 '18 at 19:56
0
There are many existing metrics packages that measure the size of methods (e.g., the Eclipse Metrics plug-in). The number of lines that constitutes a "long" method varies by language and by various authors' opinions (e.g., see this book on OO metrics).

kc2001
- 5,008
- 4
- 51
- 92