Author: Brandon Pearman

The views expressed here are mine alone and do not reflect the view of my employer.

Cyclomatic complexity is a calculation to determine the amount of paths in code. It is sometimes refered to as McCabe complexity, since it was developed by Thomas J. McCabe, is defined by M = E − N + 2

Conditionals and loops increase complexity. The reason is because the more paths your code takes the more you have to consider when coding and testing. For example:

if (a > c)
else if (c > b)

With the code above you have to test three different scenarios and keep context of them when coding. Microsoft's recommended maximum score for cyclomatic complexity is 25 per method, but many professionals work on a maximum score of 10 per method.

There are code analyzers which do cyclomatic complexity for you, some example for Dot Net there is:

Cyclomatic complexity is just to help guage the complexity, it is not perfect on its own and many tools are not perfect (See gitlab C# code on poor reduced cyclomatic Complexity which shows how to reduce the cyclomatic complexity score but make poorer code).

Check out these links for more info:

My design and architecture repo