Code quality and technical debt

Cyclomatic complexity density

Also known as Cyclomatic complexity density, Cyclomatic complexity density in software engineering

By WeavePublished 1 min read

Definition

Cyclomatic complexity normalized by a measure of code size.

What it means

Cyclomatic complexity density relates the number of independent control-flow paths to a method’s size. Normalization can make comparisons between small and large routines more useful than raw complexity alone. Because formulas and size units differ, teams should record the exact calculation and avoid comparing reports from incompatible tools.

Example

A small validation function with six branches may have a higher density than a larger orchestration routine with the same total complexity. The team reviews the compact function first because each branch occupies more of the reader’s attention.

Limitations

Density can penalize concise but well-structured code and miss complexity hidden behind calls. It also does not measure domain difficulty, defect history, or test adequacy. Use it as a triage signal.

How to use the signal

Weave can place density spikes next to review duration, test feedback time, and rework. Keep complexity computation in the analysis pipeline and use delivery history to test whether the signal predicts local friction.

How this relates to Weave

Weave can place density spikes next to review duration, test feedback time, and rework. Keep complexity computation in the analysis pipeline and use delivery history to test whether the signal predicts local friction.

Explore Engineering intelligence

Sources and further reading

  1. SonarSource code metrics and analysis documentation