BloatersHigh

Long Method: What It Costs and How to Fix It

Methods that have grown too long to understand at a glance, typically exceeding 20-30 lines.

Model cost, team of 8$6K-$24K/yr
Severity
4/5
CategoryBloaters
Detection4 tools

What It Is

A Long Method is any function or method that has accumulated so many lines of code that reading it requires scrolling, mental bookmarking, and significant cognitive effort. The threshold varies by language and team convention, but most static analysis tools flag methods above 20-30 lines. The problem is not length itself but the number of distinct responsibilities hidden inside a single method. When a method does five things, every developer who touches it must understand all five, even if they only need to change one.

Threshold: Most teams flag methods above 30 lines as warranting review. Methods above 50 lines are nearly always worth splitting. The key indicator is not raw line count but the number of distinct responsibilities.

Why It Costs Money

1

Every developer who reads the method must hold the entire control flow in working memory. The more distinct responsibilities a method mixes, the more state and branching a reader has to track before changing any one line.

2

Long methods resist unit testing. When a method has multiple code paths interleaved together, achieving full branch coverage requires complex test setups with many mocks. Untested branches inside the method are where regressions slip through.

3

Larger units carry more defects in absolute terms, so a long method tends to be where a module's bugs are found and fixed. The bugs hide in the interactions between the method's many responsibilities.

Specific Cost Mechanisms

  • ●Developer comprehension time: extra minutes per developer per week for each long method in active development
  • ●Bug clustering: defects concentrate in the long methods that change most, and each one has to be traced through the whole method to fix
  • ●Code review delays: reviewers must understand the full method to verify any change inside it

Estimated Annual Cost

Cost of one instance a year by team size, from our model at $180K fully-loaded cost per engineer. Low and high use the bottom and top of the High inputs; mid is halfway. See full methodology.

Team SizeLowMidHigh
3 devs$3K$7K$11K
5 devs$4K$10K$16K
8 devs$6K$15K$24K
10 devs$7K$19K$30K
20 devs$14K$35K$57K

These are model outputs, not measurements. Every input is on the cost model page, and the same model produces the figures on the 22 smells page. Put in your own team and cost in the smell profile calculator.

How to Detect It

Specific rules and thresholds for automated detection. See full tool comparison.

SonarQube
squid:S138 / squid:S1151

Function length threshold (default 200 lines, recommend lowering to 30)

CodeClimate
method-lines

Default threshold 25 lines, configurable per language

ESLint
max-lines-per-function

Set max to 30-40 for JS/TS codebases

PMD
ExcessiveMethodLength

Default threshold 100 lines

Refactoring Patterns

Proven techniques to eliminate this smell. See all refactoring patterns.

Extract Method

Identifiable blocks of code that serve a single purpose within the long method

Effort (our estimate): 15-45 minutes per extraction
Impact: Each extracted block gets a name that explains its intent

Replace Temp with Query

Temporary variables used to store intermediate calculations that could be separate methods

Effort (our estimate): 10-20 minutes per variable
Impact: Eliminates hidden dependencies between code blocks

Decompose Conditional

Complex if/else chains with substantial bodies

Effort (our estimate): 20-60 minutes per conditional
Impact: Moves branch bodies into named methods, lowering the complexity of the original

Related Smells

Updated November 2026