Is Cyclomatic Complexity of '267' better?

4.2k views Asked by At

I have developed an application in .NET using C#.

Using 'Calculate code metrics' option, I got the cyclomatic complexity score of '267' with 2,348 lines of code and Depth of Inheritance = 7, Class Coupling = 150 and Maintainability index = 80.

I know the lower the cyclomatic complexity, the better it is. Though I am unaware of the rest of the parameters, I wish to know if the cyclomatic complexity of 267 is better or not?

1

There are 1 answers

2
Frederick Kautz On BEST ANSWER

Cyclomatic complexity typically refers to the number of independent paths through your code. This is measured by the following formula in Visual Studio:

Complexity = Edges - Nodes + 1

For any given method, 25 is considered to be dangerously high and causes Visual Studio to throw an error. Ideally, you want to keep cyclomatic complexity as low as possible. Try aiming for 3-4 and maxing out at around 10.

For an entire project, this number is likely not meaningful enough to compare between separate projects. If you are refactoring code, you can use this as a metric to help identify whether you are having an impact on reducing overall complexity.

However, be careful with using these types of metrics as the sole indicator of a project's health. Without a clear question or goal, they can mislead you and waste time or worse. You may be better off focusing on another metric like code coverage before trying to reduce cyclomatic complexity.

You can read more about cyclomatic complexity here:
http://msdn.microsoft.com/en-us/library/ms182212.aspx
https://en.wikipedia.org/wiki/Cyclomatic_complexity