What is Cyclomatic Complexity?

Question
What is cyclomatic complexity or McCabe's complexity?

Answer
It refers to the number of times a line of source code is entered in its execution.

Number of executionsLevel of complexity
1 to 10 Not complex
11 to 20Moderately complex
21 to 50Really complex
More than 50Too complex

It is advisable to endeavor to keep the cyclomatic complexity as low as possible (according to this external site); you may want to refactor code beyond a certain threshold. The chart was adapted/taken from pages 474 and 475 of Expert Python Programming.

Leave a comment

Your email address will not be published. Required fields are marked *