Cyclomatic Complexity Vocabulary
5 exercises — master the language engineers use in code reviews to discuss complexity scores, thresholds, and refactoring strategies.
0 / 5 completed
1 / 5
A tech lead comments on a pull request: "This function has a complexity score of 15 — it exceeds our threshold of 10. Please refactor before we merge." What does this comment communicate, and what is the engineer expected to do?
"Complexity score" in code review context nearly always refers to cyclomatic complexity — the number of linearly independent paths through a unit of code.
Why "exceeds threshold" is the critical phrase:
Most teams set a quality gate — a hard limit that blocks merging — when complexity exceeds 10 (the widely cited McCabe recommendation). "Exceeds threshold" signals that the build quality gate has failed or will fail.
Common refactoring patterns to reduce complexity:
• Extract method — move a nested conditional block into a well-named private function; reduces decision points in the original
• Replace nested conditional with guard clauses — early returns flatten nesting and remove else branches
• Replace conditional with polymorphism — eliminate switch/if-else chains via strategy or command pattern
• Decompose conditional — extract complex boolean expressions into named predicate functions
How to talk about this in a code review:
• "The cyclomatic complexity exceeds our agreed threshold of 10 — this needs to be reduced before merge."
• "I'd suggest extracting the inner loop logic into a separate method to bring the complexity score down."
• "Can you add a refactoring task to the PR to address the complexity? It's blocking the quality gate."
Key vocabulary:
• Complexity score — informal term for cyclomatic complexity measurement
• Exceeds threshold — the measured value is above the agreed-upon maximum; action required
• Quality gate — an automated check that blocks merge/deploy when a metric exceeds a threshold
• Refactoring — restructuring code without changing external behaviour, with the goal of improving a quality metric
Why "exceeds threshold" is the critical phrase:
Most teams set a quality gate — a hard limit that blocks merging — when complexity exceeds 10 (the widely cited McCabe recommendation). "Exceeds threshold" signals that the build quality gate has failed or will fail.
Common refactoring patterns to reduce complexity:
• Extract method — move a nested conditional block into a well-named private function; reduces decision points in the original
• Replace nested conditional with guard clauses — early returns flatten nesting and remove else branches
• Replace conditional with polymorphism — eliminate switch/if-else chains via strategy or command pattern
• Decompose conditional — extract complex boolean expressions into named predicate functions
How to talk about this in a code review:
• "The cyclomatic complexity exceeds our agreed threshold of 10 — this needs to be reduced before merge."
• "I'd suggest extracting the inner loop logic into a separate method to bring the complexity score down."
• "Can you add a refactoring task to the PR to address the complexity? It's blocking the quality gate."
Key vocabulary:
• Complexity score — informal term for cyclomatic complexity measurement
• Exceeds threshold — the measured value is above the agreed-upon maximum; action required
• Quality gate — an automated check that blocks merge/deploy when a metric exceeds a threshold
• Refactoring — restructuring code without changing external behaviour, with the goal of improving a quality metric