Cyclomatic Complexity
Cyclomatic Complexity
Dan Fleck
Fall 2009
What is it?
A software metric used to measure the
complexity of software
Developed by Thomas McCabe
Described (informally)
as the number of
simple decision
points + 1
Coming up: What is it?
What is it?
Essentially the number of linearly
independent paths through the code
The code has no decision statements:
complexity = 1
The code has an if statement, there are two
paths through the code: complexity = 2
Convert
To
Graph Complexity
(Cyclomatic Complexity)
A number of industry studies have indicated
that the higher V(G), the higher the probability
or errors.
modules
V(G)
modules in this range are
more error prone
Since V(G) = 4,
there are four paths
4
5
Path 1:
Path 2:
Path 3:
Path 4:
1,2,3,6,7,8
1,2,3,5,7,8
1,2,4,7,8
1,2,4,7,2,4,...7,8
V(G) = 2 decisions + 1 = 3
Comment density
Coupling
Depth of inheritance,