
“But, this is a really long coroutine that has a bunch of tasks to do!” I tell myself, while trying to deny that the code I wrote is mathematically bad, to the point where Visual Studio throws a warning. You may be sent directly into the five stages of grief at the result. Here, Visual Studio pointed out a 400 line method of mine that scored a whopping 72 on the complexity scale as well as a 14/100 on the maintainability index (presented as a yellow triangle danger sign), and references 65 different classes. But, in general, it’s still quite useful for getting a roundabout sense of how complex a program is.Īlongside complexity, Visual Studio also presents a “Maintainability Index” which scores the method from 0-100 on high easily it can be maintained, as well as “Class Coupling,” which lists how many classes are referenced from that function or class. Of course, you can still have terrible code with low complexity, or decent code with high complexity. It’s a very basic metric and looks over the nuance of the code itself. Is Cyclomatic Complexity Useful?Ĭyclomatic complexity isn’t a perfect metric.

If a function calls another function that has a high cyclomatic complexity, it’s only counted as a single node, and doesn’t add anything to the caller, despite technically adding complexity to the program in a general sense.


Public void TestFunction ( string arg ) Ĭyclomatic complexity is only calculated within the scope of the function.
