Code Quality Metrics Vocabulary
0 / 5 completed
Exercise 1 of 5
The tech lead reviews a PR: 'This function has cyclomatic complexity of 15. Every if, else if, for, while, and logical operator adds 1. We cap it at 10 — above that it needs 15 test cases just for branch coverage.'
What does cyclomatic complexity measure?
Cyclomatic complexity (McCabe, 1976) counts linearly independent paths. A function with complexity 15 needs 15 tests for full branch coverage. Keep it under 10.
Exercise 2 of 5
The QA lead explains: 'We have 78% line coverage but low branch coverage. Line coverage hits both sides of an if block if you test x=1, but the else branch is never executed — branch coverage catches that gap.'
What is the key difference between line coverage and branch coverage?
Line coverage measures which lines were executed. Branch coverage measures whether both true and false paths of each conditional were tested — it's a stronger guarantee.
Exercise 3 of 5
The architect says: 'We want high cohesion and low coupling. High cohesion means a class does one thing well. Low coupling means modules don't depend on each other's internals — changes don't cascade.'
Why is high cohesion desirable?
High cohesion means all code in a module serves a single, well-defined purpose. God classes with low cohesion are hard to test and change without side effects.
Exercise 4 of 5
The senior dev explains to the PM: 'Prudent deliberate debt — we know we are cutting corners, we'll fix it after launch. Reckless inadvertent debt — we wrote bad code without knowing there was a better approach.'
What does the technical debt quadrant (Martin Fowler) help teams do?
The debt quadrant classifies debt by deliberate/inadvertent and prudent/reckless. This helps teams communicate the nature and urgency of debt to both engineers and stakeholders.
Exercise 5 of 5
The team's SonarQube build fails: 'Quality gate failed — new code coverage 62%, below the 80% threshold. Three new critical code smells. Maintainability rating C. No merge until these pass.'
What is a quality gate in a CI/CD pipeline?
A quality gate is an automated policy check (coverage, code smells, security issues, duplications) enforced in CI. Code that fails the gate cannot be merged until violations are fixed.