Is S3776 the new S1541?

Rules java:S3776 and java:S1541 both deal with complexity of methods, and have similar descriptions. The former, but not the latter, is activated in Sonar way; the latter is on in our QP because we upgraded from older versions of SQ. When I tried activating both in an experiment, the issue count differed by less than 1%, even though the thresholds were different (the default value was used for both).

So should I just replace S1541 with S3776 as the preferred version? As of 8.6, the description of S1541 doesn’t say anything about being replaced, and isn’t deprecated.

Hello @MisterPi

The two rules target different kinds of complexity: Cyclomatic and Cognitive.

To understand the difference, I suggest you to have a look at the different resources available discussing the topic:

In just a few words:

Cyclomatic Complexity is about testability - what’s your minimum number of unit tests to exercise all the code? Cognitive Complexity is about understandability.

Today, only the rule using Cognitive Complexity is enabled by default, as we believe it is best suited for the purpose of having clean code.
Still, the rule using Cyclomatic Complexity is available if you need this measure.

Hope it clarifies the situation.

1 Like

OK, thanks for clarifying. They do seem to go together most of the time. For us, close to 90% of the issues for one of the rules are also in the other.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.