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.
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.
Continuous Delivery 2.0
Tech and case studies on organizational management, team management, and engineering efficiency
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.