The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Questions tagged [cyclomatic-complexity]

The tag has no usage guidance.

30 questions
Filter by
Sorted by
Tagged with
79 views

### Summing cyclomatic complexity of function or files

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 ...
55k views

### 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 ...
10k views

### if and else or if an 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 ...
625 views

### Cyclomatic complexity while protecting input

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 &&...
3k views

### 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 ...
302 views

### Are short-circuiting paths considered for path coverage?

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 ...
342 views

### How to compute cyclomatic complexity for empty whiles and if + breaks?

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 ...
399 views

### Cyclomatic Complexity Question

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 *...
5k views

### 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? ...
5k views

### 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 ...
662 views

### Code pattern to have the least possible code complexity (Javascript)

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 ...
783 views

### Relation between LOC and Cyclomatic Complexity

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?
4k views

### Keep indentation level low [duplicate]

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 ...
70 views

### Can basis path technique (derived from cyclomatic complexity) be used on non-source code?

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 ...
426 views

### Calculating cyclomatic complexity/ mccab's number

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 ...
3k views

### 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 ...
4k views

### 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 ...
705 views

### 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. ...
273 views

### What are the potential tradeoffs for lower down Cyclomatic Complexity

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 ...
645 views

### Can we have a negative cyclomatic complexity?

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 ...
47k views

### 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 ...
3k views

### Approaches to reduce cyclomatic complexity

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 ...
3k views

### Is cyclomatic complexity density a good software quality metric? [duplicate]

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 ...
148 views

### Cyclomatic complexity for 2 IFs - why not just FF or TT?

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 ...
4k views

### equals and hashcode methods autogenerated, is it always a good practice?

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 ...
2k views

### 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. ...
3k views

### 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 ...
2k views

### 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 ...