Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [cyclomatic-complexity]

Filter by
Sorted by
Tagged with
3 votes
2 answers
146 views

Wikipedia says that following program has cyclomatic complexity of 3 Given that formula is V-E+2P, the answer is definitely 3 (9 - 8 + 2*1 = 3). Alternative definition says: Number of tests to cover ...
IndustryUser1942's user avatar
3 votes
4 answers
479 views

I have a function (written in Python) that processes a loosely structured log file. The log file would have begin-end markers for different sections, with each section describing different things (e.g....
Happy Green Kid Naps's user avatar
3 votes
1 answer
451 views

For the example shown below, in which I added the True and False values over the original document (so if something is wrong there, it's probably my fault), I understand there should be seven states ...
Alfred Kaminski's user avatar
0 votes
3 answers
727 views

Prompted by Sonar, I am looking to reduce the complexity of a function (one that some might call arrow code). I am loosely familiar with some of the principles of reducing arrow code complexity (...
j.k's user avatar
  • 111
-1 votes
1 answer
207 views

I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
AnOldSoul's user avatar
  • 173
2 votes
0 answers
164 views

Assume the flow graph of a function is below (sorry I have forgotten the code of the function): And when I try to calculate the cyclomatic complexity: When I use the edge and node to calculate it, V(...
Paul Zhang's user avatar
4 votes
2 answers
2k views

Is the sum of the cyclomatic complexity of all section in a file the total cyclomatic complexity for this file? If it is, is the sum of a set of related files the total cyclomatic complexity for this ...
cervh's user avatar
  • 83
12 votes
2 answers
54k views

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 ...
Orici's user avatar
  • 237
3 votes
4 answers
1k views

In a book Doron A. Peled, he states that " path coverage does not subsume multiple condition coverage because you can execute all the paths without exercising all the conditions. But I believe ...
John V's user avatar
  • 4,946
1 vote
1 answer
1k views

This is closely related to this question which asks about the complexity of the following: while (x > level) x = x – 1; x = 0 Using the graph method it has a Complexity = 2. Fred Swartz ...
Alexei's user avatar
  • 452
3 votes
1 answer
1k views

I have a general question pertaining to Cyclomatic Complexity. Please have a look at the attached source code: private void downShift(int index) { // index of "child", which will be either index *...
Al-geBra's user avatar
0 votes
3 answers
1k views

I've been looking for the ideal coding patterns used to score well in a Cyclomatic Complexity. Of course, code will be subject to change according to what is being developed but regardless the ...
Matthew Barbara's user avatar
0 votes
2 answers
2k views

Is there something that ratio of the metrics LOC and Sum Cyclomatic Complexity in a project with many modules can talk about? Does it show the logical complexity of a module/project?
Christy Wald's user avatar
1 vote
1 answer
91 views

I know that McCabe basis path testing ensures that all linearly independent paths are tested, making sure that all code branches were covered in an effective manner. But nowadays, I doubt anybody ...
John V's user avatar
  • 4,946
0 votes
1 answer
2k views

if field is blank or in form print "enter again" else if no credit and debit < 1000 print "less amount" else print "accessed" end if end if I'm very confused in calculating the cyclomatic ...
user7943804's user avatar
8 votes
3 answers
4k views

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 ...
Johnny's user avatar
  • 91
10 votes
7 answers
6k views

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 ...
Yassine Badache's user avatar
3 votes
5 answers
827 views

I need to reduce the cyclomatic complexity of my input tests. I have no control over the inputs, so I have to go through all of these checks. if(y1 < 2000 || y2 < 2000 || !(m1 >= 1 &&...
Petr D. Svoboda's user avatar
5 votes
3 answers
2k views

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. ...
GuardianX's user avatar
  • 171
4 votes
4 answers
676 views

Since high Cyclomatic Complexity is harmful, and it would be beneficial to lower it down by creating sub functions. However, it might lead to a long calling queue and lead to some super nested ...
Jiahang Li's user avatar
4 votes
3 answers
2k views

I am having a hard time to understand cyclomatic complexity. I went through some videos in youtube for this. I got negative value for cyclomatic complexity when I use this formula M = E - N + P. I ...
Jay Jay's user avatar
  • 41
6 votes
3 answers
7k views

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 ...
VincentZHANG's user avatar
3 votes
2 answers
4k views

Where I define Cyclomatic complexity density as: Cyclomatic complexity density = Cyclomatic complexity / Lines of code I was reading previous discussions about cyclomatic complexity and there seems ...
redcalx's user avatar
  • 375
1 vote
1 answer
420 views

I know that cyclomatic complexity defines the number of independent paths in the code. Using the simple way, it can be calculated as number of IF +1. In that case, for a simple code with two IFs, CC ...
user144171's user avatar
3 votes
1 answer
5k views

Preamble: Let's say I aim to cover all my classes with test coverage. Despite the common opinion (expecially in Java community) to "not pay too much attention to Cyclomatic Complexity (CC) and code ...
thermz's user avatar
  • 320
16 votes
5 answers
9k views

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 ...
reox's user avatar
  • 293
12 votes
2 answers
3k views

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. ...
Simon Forsberg's user avatar
23 votes
7 answers
54k views

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 ...
asyncwait's user avatar
  • 407
5 votes
1 answer
4k views

I was running our code through JSHint, and decided to switch checks against cyclomatic complexity, and then went on long refactoring sprint. One place though baffled me, here is a code snippet: var ...
David Sergey's user avatar
11 votes
6 answers
4k views

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 ...
C. Ross's user avatar
  • 2,926
7 votes
2 answers
4k views

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 ...
John V's user avatar
  • 4,946
10 votes
2 answers
5k views

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 ...
throp's user avatar
  • 209
8 votes
1 answer
2k views

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 ...
Dominik G's user avatar
  • 255
13 votes
3 answers
7k views

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? ...
VirtuosiMedia's user avatar
55 votes
4 answers
115k views

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 ...
AngryBird's user avatar
  • 1,815
11 votes
4 answers
4k views

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 ...
Arseni Mourzenko's user avatar