Cyclomatic complexity
Cyclomatic complexity is a software metric that measures the number of linearly independent execution paths through a program's control-flow graph.
Practices of the Python Pro
Cyclomatic complexity is a software metric that measures the number of linearly independent paths through a program's control-flow graph.
- How it is used
- Guides maintainability work by revealing functions whose branching and looping deserve refactoring attention.
- How deep it goes
- Defines execution paths, sketches control-flow graph counting, and demonstrates refactoring, while deferring formal mathematical analysis.
- Examples
- Uses Python functions for long-word detection, GitHub-star importing, and response formatting with JSON, XML, and configuration mappings.
- What you can do after
- Diagnose/debug with it by spotting path-heavy functions, measuring them manually or with Radon and SonarQube, and reducing branching through refactoring.
Read how Practices of the Python Pro explains cyclomatic complexity →
Unit Testing Principles, Practices, and Patterns
Cyclomatic complexity is a metric that counts the independent control-flow paths or branching structure in a program or method.
- How it is used
- Uses branching structure to classify code and guide unit-testing and refactoring priorities.
- How deep it goes
- Defines the formula, independent-path interpretation, and compound-predicate counting, but does not develop a broader measurement system.
- Examples
- Uses a branch-free method and an AND condition to demonstrate complexity calculations.
- What you can do after
- Evaluate branching complexity and estimate the tests associated with complete branch coverage.
Read how Unit Testing Principles, Practices, and Patterns explains cyclomatic complexity →
Functional Programming in JavaScript
A software metric that counts the number of linearly independent paths through a program’s control flow.
- How it is used
- Measures control-flow complexity when comparing imperative and functional implementations.
- How deep it goes
- Defines independent execution paths and compares measured values, without deriving the metric calculation.
- Examples
- Uses the imperative and functional showStudent implementations and their metric comparison.
- What you can do after
- Evaluate implementations by comparing their control-flow complexity and related static metrics.
Read how Functional Programming in JavaScript explains cyclomatic complexity →
The Art of Code
Cyclomatic complexity is a software metric that counts the independent execution paths through a program's control flow based on its decision points.
- How it is used
- Quantifies control-flow complexity for code review, static analysis, and maintainability investigation.
- How deep it goes
- Defines independent execution paths and decision-point counting, but stops short of capturing readability, nesting, or Boolean entanglement fully.
- Examples
- Uses if, while, and switch statements as decision-point examples and contrasts equal scores with different readability costs.
- What you can do after
- Evaluate methods with a structural metric and investigate whether refactoring or complexity containment is appropriate.
AI-Powered Developer: Build software with ChatGPT and Copilot
Cyclomatic complexity is a metric that counts the independent execution paths through a software module based on its decision points.
- How it is used
- Uses decision-path complexity to assess code quality, maintainability, and likely testing effort.
- How deep it goes
- Defines independent paths and connects higher values to maintenance and testing difficulty, but does not derive a calculation formula.
- Examples
- Uses Copilot questions about the Department-StatisticsVisitor class and an observed complexity value of 1.
- What you can do after
- Evaluate code structure with a complexity reading and identify when additional testing or simplification may be warranted.
Also covered in
- Grokking Software ArchitectureIn early access (MEAP)
- The Art of Unit Testing 3e
- Write Powerful Rust Macros
What to know first
- control flowControl flow is the order and branching of execution that determines which operations in a program or process run and when.
- maintainabilityMaintainability is the degree to which software can be understood, modified, corrected, tested, or kept operational with reasonable effort over time.
Related concepts
- complexitykind of · Complexity is the degree to which interacting elements or factors make a system or problem difficult to understand, predict, change, operate, or solve.
- complexity metrickind of · A complexity metric is a quantitative measure of the structural intricacy or difficulty of understanding, modifying, or executing software code.
- maintainability indexuses · The maintainability index is a composite software metric that estimates how easily code can be understood, modified, and maintained.
- cognitive complexityalternative to · Cognitive complexity is the mental effort required to understand code, especially as its control flow and reasoning paths become more complex.
Questions about cyclomatic complexity
What is cyclomatic complexity?
Cyclomatic complexity is a software metric that measures the number of linearly independent execution paths through a program's control-flow graph.
Which Manning books explain cyclomatic complexity?
Practices of the Python Pro, Unit Testing Principles, Practices, and Patterns, Functional Programming in JavaScript, The Art of Code and AI-Powered Developer: Build software with ChatGPT and Copilot.
What should I know before learning cyclomatic complexity?
Manning books that teach cyclomatic complexity usually introduce control flow and maintainability first.
What is the difference between cyclomatic complexity and cognitive complexity?
Cyclomatic complexity is a software metric that measures the number of linearly independent execution paths through a program's control-flow graph. Cognitive complexity is the mental effort required to understand code, especially as its control flow and reasoning paths become more complex.
What is cyclomatic complexity a kind of?
Cyclomatic complexity is a kind of complexity. Complexity is the degree to which interacting elements or factors make a system or problem difficult to understand, predict, change, operate, or solve.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




