Reduce Cyclomatic Complexity

Cyclomatic complexity was first described by Thomas J. McCabe in his December 1976 paper “A Complexity Measure.”[48] It represents the number of paths through code.

Code with just one conditional or if statement has a cyclomatic complexity of two—there are two possible paths through the code and therefore two possible behaviors the code can produce. If there are no if statements, no conditional logic in code, then the code has a cyclomatic complexity of one. There’s only one possible behavior the code can produce. But this grows exponentially. Two if statements have a cyclomatic complexity of four, three have a cyclomatic complexity of eight, and so on. Drive cyclomatic complexity down to as low as you can because, ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.