How to Calculate the Cyclomatic Complexity


Software development can be enormously complex, but there are certain techniques that help minimize how unwieldy the source code of a given program becomes. You can organize the code into modules or classes, use intuitive naming conventions for functions and variables or minimize the Cyclomatic Complexity. The Cyclomatic Complexity of a program is a measure of how many "decisions" it must make. The fewer decisions, such as a if/then statement, the simpler the program is, and therefore the less prone to errors and more understandable it is.

  • Count the number of if/then statements in your program. Count each elseif/then statement as a separate one, then total the number.

  • Find any select (also know as switch) statements, and count the number of cases within them. Find the total of the the cases in all the select statements combined. Do not count the default or "else" case.

  • Count all the loops in your program. Ignore loops that are unconditional (i.e. loops that are infinite).

  • Count all the try/catch statements.

  • Add the numbers from the previous 4 steps together, then add 1. This is the cyclomatic complexity of your program.

Related Searches


Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!