Glossary
By Glue Team
Code quality metrics are measurable indicators that show the health and maintainability of software code. They quantify aspects like complexity, test coverage, duplication, and adherence to standards—transforming vague notions of "good code" into concrete, trackable data.
Poor code quality creates exponential costs:
Code quality metrics let teams see these costs quantified and track improvement over time.
Cyclomatic complexity: Counts decision paths in code. A function with 15 conditions has higher complexity than one with 2. Complexity > 10 predicts bugs; > 20 predicts maintenance nightmares.
Test coverage: Percentage of code executed by tests. 80%+ coverage correlates with 50% fewer production bugs. Note: coverage measures execution, not test quality; two tests with 80% coverage can have vastly different bug detection rates.
Code duplication: Repeated code is a liability—when you fix a bug in one place, you must find and fix it everywhere it's duplicated. Duplication > 10% signals refactoring need.
Dependency coupling: How many other modules depend on this code? High coupling makes changes risky; low coupling enables rapid iteration.
Code churn: How often does the same code get modified repeatedly? High churn signals unclear requirements or architectural problems.
SLOC per function: Lines of code per function. Functions > 200 LOC are hard to test and understand; < 50 LOC are more maintainable.
Metrics are only valuable if they drive action. Common approaches:
Set thresholds: "We accept < 50 LOC per function and > 80% test coverage." New code violating thresholds gets feedback in review.
Track trends: Monitor whether cyclomatic complexity is rising (bad) or falling (good). A 5% quarterly improvement is significant.
Connect to business impact: When a module with high complexity produces 10x more bugs, leadership understands why refactoring matters.
Automate enforcement: CI/CD blocks merges that violate quality thresholds, shifting quality left.
Q: What's the difference between code quality and code performance? A: Quality measures maintainability and correctness; performance measures speed and resource use. Good quality code can have poor performance, and vice versa.
Q: Should we refactor just to improve metrics? A: No. Refactor when metrics reveal actual risks: high complexity in code that changes frequently, low coverage in critical paths, or duplication causing bugs.
Q: How often should we measure code quality? A: Continuously. Metrics should be visible in dashboards, updated after each merge, so trends are visible and improvements are rewarded in real-time.
Keep reading