Fundamentals 4 min read

Four Essential Code Quality Metrics and How to Manage Them

This article introduces four widely‑accepted code‑quality indicators—cyclomatic complexity, function length, file duplication rate, and class fan‑in/fan‑out ratio—explains how to set thresholds, compare error density across codebases, and apply practical management strategies without degrading quality.

Continuous Delivery 2.0
Continuous Delivery 2.0
Continuous Delivery 2.0
Four Essential Code Quality Metrics and How to Manage Them

Using four engineer‑approved code‑quality metrics, you can evaluate whether your code quality is five times worse than Google's open‑source standards.

The four basic indicators are:

Function (method) cyclomatic complexity

Total lines per function (method)

Duplication rate within a single file

Class fan‑in/fan‑out ratio (for Java code)

After selecting appropriate thresholds for each metric, scan both codebases of comparable size and compare the results using “error density” (e.g., average errors per hundred lines) rather than raw counts. This also allows you to track how many new errors appear per additional hundred lines as the product evolves.

Once the four metrics and thresholds are agreed upon, you can manage code quality even for legacy code by applying the “Scout Camp principle”: avoid letting quality deteriorate further.

Choosing suitable thresholds is up to you; for example, the article shows a preferred cyclomatic‑complexity threshold chart. The measured cyclomatic complexity can be interpreted as the number of test cases needed for a function because it corresponds to the number of execution paths.

Thresholds may differ by language—C++ typically warrants higher limits due to inherent complexity.

Do not rely on average cyclomatic complexity, as it masks high‑complexity outliers and may be misleading; a few complex functions can be acceptable for performance reasons even if they exceed the threshold.

code qualitycyclomatic complexitySoftware Metricscode duplicationthreshold management
Continuous Delivery 2.0
Written by

Continuous Delivery 2.0

Tech and case studies on organizational management, team management, and engineering efficiency

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.