Cyclomatic Software Complexity Measure
A Cyclomatic Software Complexity Measure is a software complexity measure within program control flows that aims to quantify programming complexity through linearly independent path counts (developed by Thomas J. McCabe, Sr. in 1976).
- AKA: Cyclomatic Complexity, McCabe Complexity, Control Flow Complexity Measure, Cyclomatic Number.
- Context:
- It can typically measure Program Control Flow Complexity through control-flow graph analysis.
- It can typically calculate Linearly Independent Paths using graph theory principles.
- It can typically assess Code Maintainability Risk via cyclomatic complexity thresholds.
- It can typically guide Software Testing Strategy through basis path testing.
- It can typically indicate Refactoring Need by cyclomatic complexity score evaluation.
- ...
- It can often predict Software Defect Density through cyclomatic complexity-defect correlations.
- It can often support Code Review Process via cyclomatic complexity hotspot identification.
- It can often enable Software Quality Assessment by cyclomatic complexity trend analysis.
- It can often facilitate Development Effort Estimation through cyclomatic complexity-effort relationships.
- ...
- It can range from being a Simple Cyclomatic Software Complexity Measure to being a Extended Cyclomatic Software Complexity Measure, depending on its cyclomatic complexity calculation variant.
- It can range from being a Function-Level Cyclomatic Software Complexity Measure to being a System-Level Cyclomatic Software Complexity Measure, depending on its cyclomatic complexity measurement scope.
- It can range from being a Manual Cyclomatic Software Complexity Measure to being an Automated Cyclomatic Software Complexity Measure, depending on its cyclomatic complexity calculation method.
- ...
- It can be computed as V(G) = E - N + 2P, where E is edge count, N is node count, and P is connected component count.
- It can alternatively be calculated as V(G) = D + 1, where D is decision node count.
- It can have McCabe Thresholds such as 1-10 (simple), 11-20 (moderate), 21-50 (complex), and [[>50 (untestable)]].
- It can correlate with Lines of Code (LOC) but measure different complexity aspects.
- It can be implemented in Static Analysis Tools for automated complexity measurement.
- It was developed by Thomas J. McCabe, Sr. in 1976 as part of structured testing methodology.
- It forms the basis for Basis Path Testing where test case count equals cyclomatic complexity.
- ...
- Example(s):
- Basic Cyclomatic Software Complexity Examples, such as:
- Linear Code Sequence with cyclomatic complexity = 1 (no branches).
- Single If Statement with cyclomatic complexity = 2 (one decision point).
- If-Else Statement with cyclomatic complexity = 2 (one decision, two paths).
- While Loop with cyclomatic complexity = 2 (loop condition check).
- Moderate Cyclomatic Software Complexity Examples, such as:
- High Cyclomatic Software Complexity Examples, such as:
- Tool-Based Cyclomatic Software Complexity Measurements, such as:
- ...
- Basic Cyclomatic Software Complexity Examples, such as:
- Counter-Example(s):
- Lines of Code (LOC) Measure, which counts code statements rather than control flow paths.
- Halstead Complexity Measures, which analyze operator and operand usage rather than control structures.
- Computational Complexity Measures, which assess algorithm resource requirements rather than code structure.
- Coupling Metrics, which measure module interdependence rather than internal complexity.
- Cohesion Metrics, which evaluate functional relatedness rather than control flow complexity.
- See: Basis Path Testing, Software Metric, Programming Complexity, Control-Flow Graph, Function (Computer Science), Modular Programming, Codepath, Software Complexity Measure, Software Engineering-Related Measure, Code Quality Metric, Software Engineering Productivity Measure, Software Size Measure.
References
2023
- (Wikipedia, 2023) ⇒ https://en.wikipedia.org/wiki/Cyclomatic_complexity Retrieved:2023-7-7.
- Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976.
Cyclomatic complexity is computed using the control-flow graph of the program: the nodes of the graph correspond to indivisible groups of commands of a program, and a directed edge connects two nodes if the second command might be executed immediately after the first command. Cyclomatic complexity may also be applied to individual functions, modules, methods or classes within a program.
One testing strategy, called basis path testing by McCabe who first proposed it, is to test each linearly independent path through the program; in this case, the number of test cases will equal the cyclomatic complexity of the program.
- Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976.
2016
- (Ebert et al., 2016) ⇒ Ebert, C., Cain, J., Antoniol, G., Counsell, S., ... (2016). “Cyclomatic complexity". IEEE Software.
- QUOTE: "IN ANSWERING WHY cyclomatic complexity (CC) is so widely employed in industry but … the question, what parts of the software industry are even aware of current software research? …"
2015
- (Sculley et al., 2015) ⇒ D. Sculley, Gary Holt, Daniel Golovin, Eugene Davydov, Todd Phillips, Dietmar Ebner, Vinay Chaudhary, Michael Young, Jean-Francois Crespo, and Dan Dennison. (2015). “Hidden Technical Debt in Machine Learning Systems.” In: Proceedings of the 28th International Conference on Neural Information Processing Systems.
- QUOTE: ... For any individual change, the cost of experimenting in this manner is relatively low — none of the surrounding infrastructure needs to be reworked. However, over time, these accumulated codepaths can create a growing debt due to the increasing difficulties of maintaining backward compatibility and an exponential increase in cyclomatic complexity. ...
2009
- (Graylin et al., 2009) ⇒ Graylin, J., Hale, J. E., Smith, R. K., David, H., Kraft, N. A., ... (2009). “Cyclomatic complexity and lines of code: empirical evidence of a stable linear relationship". Journal of Software.
- QUOTE: "Researchers have often commented on the high correlation between McCabe’s Cyclomatic Complexity (CC) and lines of code (LOC). Many have believed this correlation high enough …"
1996
- (Watson, Wallace, and McCabe, 1996) ⇒ Watson, A. H., Wallace, D. R., & McCabe, T. J. (1996). “Structured testing: A testing methodology using the cyclomatic complexity metric".
- QUOTE: "The software complexity measures described in this document are: cyclomatic complexity, module design complexity, integration complexity, object integration complexity, actual com…"
1991
- (Gill and Kemerer, 1991) ⇒ Gill, G. K., & Kemerer, C. F. (1991). “Cyclomatic complexity density and software maintenance productivity". IEEE Transactions on Software Engineering.
- QUOTE: "Whether cyclomatic complexity captures all aspects of complexity in one figure of merit, but rather to answer the question raised by Shepperd as to whether cyclomatic complexity can ..."
1988
- (Shepperd, 1988) ⇒ Shepperd, M. (1988). “A critique of cyclomatic complexity as a software metric". Software Engineering Journal. IET.
- QUOTE: "Cyclomatic complexity metric is widely cited as a useful predictor of various software ... theoretical foundations and an inadequate model of software development. The argument that the ..."