Article

What is cyclomatic complexity?

Published: 13 April 2023

Cyclomatic complexity is a metric used to measure the complexity of a software system. It is a quantitative measure of the number of independent paths through a program’s source code. It was developed by Thomas McCabe in 1976 to measure the complexity of control flow in software.

Simply, it measures the number of possible paths that can be taken through a software program. The more complex the program, the higher the cyclomatic complexity. The formula to calculate the cyclomatic complexity is:

M = E – N + 2

Where:

  • M is the cyclomatic complexity
  • E is the number of edges (control flow) in the program
  • N is the program’s number of nodes (sequential or branching statements).

A higher cyclomatic complexity indicates that the code is more difficult to understand and maintain, increasing the likelihood of bugs and errors in the software. Therefore, it is important to keep the cyclomatic complexity of a program as low as possible to ensure better code quality and maintainability.

What next?

Learn about the the pros and cons of using cyclomatic complexity as a code quality metric

Read more

Related articles...

Article
Global Drivers of Performance Series

In the ever-evolving world of software development, optimizing productivity, maintainability,…

Read More
Article
Review of “Predicting Expert Evaluations of Software Code Reviews” (Denisov et al., 2024)

We applaud the Denisov et al. (2024) initiative in highlighting…

Read More
Article
Debunking GitHub’s Claims: A Data-Driven Critique of Their Copilot Study

Generative AI (GenAI) tools like GitHub Copilot have captured the…

Read More
abstract02@2x

Bringing objectivity to your decisions

Giving teams visibility, managers are enabled to increase the velocity of development teams without risking code quality.

0

out of 10 of the worlds biggest banks

0

of the S&P Top 50 Companies

0

of the Fortune 50 Companies