Questions tagged [cyclomatic-complexity]
35 questions
54
votes
4 answers
What does the 'cyclomatic complexity' of my code mean?
I am new to static analysis of code. My application has a Cyclomatic complexity of 17,754. The application itself is only 37,672 lines of code. Is it valid to say that the complexity is high based on the lines of code? What exactly is the Cyclomatic…

AngryBird
- 1,805
- 5
- 17
- 22
23
votes
7 answers
Avoid too complex method - Cyclomatic Complexity
Not sure how to go about this method to reduce Cyclomatic Complexity. Sonar reports 13 whereas 10 is expected. I am sure nothing harm in leaving this method as it is, however, just challenging me how to go about obeying Sonar's rule. Any thoughts…

asyncwait
- 407
- 1
- 4
- 7
15
votes
5 answers
Keep indentation level low
I hear a lot that you should not write functions larger than one screen size, that you should extract things into functions if you call things very often and all these coding guidelines. One of them is also keep your indentation level low. Some…

reox
- 283
- 2
- 6
12
votes
2 answers
Cyclomatic complexity when calling same method multiple times
Thanks to a question over at Code Review I got into a little disagreement (which essentially is an opportunity to learn something) about what exactly the Cyclomatic Complexity is for the below code.
public static void main(String[] args) {
try…

Simon Forsberg
- 371
- 4
- 16
12
votes
3 answers
Understanding Cyclomatic Complexity
I've recently come across Cyclomatic Complexity and I'd like to try to understand it better.
What are some practical coding examples of the different factors that go into calculating the complexity? Specifically, for the Wikipedia equation of M = E…

VirtuosiMedia
- 4,089
- 4
- 33
- 43
11
votes
6 answers
Do iterative methods reduce cyclomatic complexity and improve supportability?
Do iterative methods such as are commonly found in modern languages such as C#, JavaScript, and (hopefully) in Java 8 reduce cyclomatic complexity's impact on understandability and supportability of code?
For example in C# we might have the…

C. Ross
- 2,926
- 2
- 26
- 42
10
votes
4 answers
Does it make sense to compute cyclomatic complexity/lines of code ratio?
In general, maintainability index relies on many factors. For example, in Visual Studio, it rely on cyclomatic complexity, depth of inheritance, class coupling and lines of code; those four values must be as low as possible.
At the same time, I've…

Arseni Mourzenko
- 134,780
- 31
- 343
- 513
10
votes
2 answers
if and else or if and return?
I have a Java method with a void type of return that checks a condition. It do something in case of true and other thing in case of false, typical if / else structure, but is possible use only the if block with a empty return in the end and omit the…

Orici
- 217
- 1
- 2
- 6
10
votes
7 answers
Why is cyclomatic complexity that important for a single method?
I am using SonarLint for Eclipse since recently, and it helped me a lot. However, it raised to me a question about cyclomatic complexity.
SonarLint considers as acceptable a C.C of 10, and there are some cases where I am beyond it, about 5 or 6…

Yassine Badache
- 391
- 1
- 3
- 11
9
votes
2 answers
How is technical debt best measured? What metric(s) are most useful?
Possible Duplicate:
How can I quantify the amount of technical debt that exists in a project?
If I wanted to help a customer understand the degree of technical debt in his application, what would be the best metric to use? I've stumbled across…

throp
- 199
- 1
- 4
8
votes
1 answer
Complexity of a web application
I am currently writing my Master's Thesis on maintainability of a web application. I found some methods like the "Maintainability Index" by Coleman et.al. or the "Software Maintainability Index" by Muthanna et.al.
For both of them one needs to…

Dominik G
- 245
- 2
- 7
7
votes
3 answers
Cyclomatic Complexity spread over non-reusable functions
I am frequently writing parser and mappers of some sort. This means that the switch statement gets used a lot and often many if statements for checking for valid input.
This of course creates a lot of cyclomatic complexity. I usually split out value…

Johnny
- 81
- 1
- 5
6
votes
3 answers
How to calculate Cyclomatic Complexity exactly?
My question is more about the transformation from programming code to control flow graph.
Say, I have a piece of code:
public class Contractor
{
// other member fields...
private bool isVerified;
private int noOfA;
private int…

VincentZHANG
- 171
- 1
- 5
6
votes
2 answers
Cyclomatic complexity with two IFs - why it is 3?
I have read an article with following example:
void func()
{
if (condition1)
a = a + 1;
if (condition2)
a = a - 1;
}
It says the CC is 3 as there are three possible paths. How come? Why not 4? I Would expect TRUE,TRUE; FALSE,FALSE; TRUE, FALSE and…

John V
- 4,898
- 10
- 47
- 73
5
votes
3 answers
Cyclomatic complexity vs performance
As far as I understand the concept, CC is determined by how many nested branched logic the given method have. It can be refactored to checking the opposite of original predicate and calling return. For example:
void Foo()
{
if (predicate0)
{
…

GuardianX
- 171
- 5