What is cyclomatic complexity and why is it important?
Cyclomatic complexity is a computer science metric (measurement) developed by Thomas McCabe used to generally calculate the complexity of a program. It directly calculates the number of linearly independent paths by a programs source code. The concept, although not the method, is somewhat similar to that of general text complexity calculated by the Flesch-Kincaid Readability Test. Cyclomatic complexity is computed using a graph that explains the control flow of the program. The nodes of the graph correspond to the commands of a program. A directed edge connects two nodes, if the second command might be implemented immediately after the first command. By definition,
CC = E - N + P
where
CC = cyclomatic complexity
E = the number of edges of the graph
N = the number of nodes of the graph
P = the number of connected components