Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
Root.Smell.Complexity.CylomaticComplexity Parent Index
Sibling aspects MaintainabilityIndex

CylomaticComplexity

Number of linearly independent paths through a program's source code.

The Cyclomatic complexity was developed by Thomas J. McCabe in 1976 and it is based on a control flow representation of the program.

Tastes

Taste Meaning Values
cyclomatic_complexity This the maximum number of embedded branches or embedded loops allowed. 6

* bold denotes default value

Subaspects

This aspect does not have any sub aspects.

Example

// The cyclomatic complexity of this program is 4.

int foo (int a, int b) {
    if (a > 17 && b < 42 && a+b < 55) {
        return 1;
    }
    return 2;
}

Importance

Very complex code are difficult to read, debug and maintain. It is always a good idea to keep things as simple as possible.

How to fix this

This can be solved by breaking down complex functions into smaller onces.