Code quality and technical debt

Method length

Also known as Method length, Method length in software engineering

By WeavePublished 1 min read

Definition

The amount of source text or statements contained in a method or function.

What it means

Method length is a simple size measure for a callable unit. It can highlight routines that combine parsing, business rules, persistence, and error handling. The number should be defined by language and tool, such as physical lines, logical statements, or tokens. Size is useful for finding review candidates, not for declaring a method incorrect.

Example

A 140-line handler validates input, queries three systems, renders a response, and records audit data. Its size prompts a decomposition discussion around responsibilities and test seams.

Limitations

Short methods can hide complexity through indirection, while a long method can be clear when it expresses one linear transformation. Generated code and formatting conventions distort raw counts. Review cohesion and branching alongside length.

How to use the signal

Read the method’s control flow and responsibilities before extracting code, because shorter text can still be harder to understand.

Weave can show whether long methods appear in larger diffs, slower reviews, or later rework. Use repository analysis to measure size and Weave to understand the delivery context surrounding the finding.

How this relates to Weave

Weave can show whether long methods appear in larger diffs, slower reviews, or later rework. Use repository analysis to measure size and Weave to understand the delivery context surrounding the finding.

Explore Engineering intelligence

Sources and further reading

  1. SonarSource code metrics and analysis documentation