I found the rule that scores 1 for a javascript function is unfair because it punishes functional programming practice of writting small composible functions
My project is getting into a state that the cyclomatic complexity is average and congnitive complexity is about 10% of average
As the congnitive complexity is claimed to be fairer and that is the case for me, why is Sonarqube keeping 2 complexity metrics anyway?
Cyclomatic Complexity is about testability - what’s your minimum number of unit tests to exercise all the code? Cognitive Complexity is about understandability. So if you’re trying to put a measurement on this (admittedly inherently subjective) value then prefer Cognitive Complexity.
I also took a look at our C# code and found out a plain DTO ended up with a complexity of 63 because each property consists of a pair of getter/setter which scores 2.
I think the rule that scores 1 for a function heavily distorts reality and should be removed
That’s just how Cyclomatic Complexity works. Remember, I said that Cyclomatic complexity is about testability. To thoroughly test your class you need at least one test case for each method, and that’s what’s being reflected in that “scores 1 for a function”.
But your perception that it “heavily distorts reality” is quite common among developers and one of the things that lead us to formulate Cognitive Complexity.
Yes, my previous statement was not accurate. Public functions / methods do increase the need of additional test cases so it makes sense to +1
The issue I have been facing is about private/internal functions. It is a good and common practice to break down a big function to small functions with single responsibility, this kind of refactoring doesn’t increase the need of test cases