Search code examples
javacode-metrics

CCN java function- is there any guide line on what could be realistic limit


I am using javancss to detect CCN of methods. There are methods in our source code with values varying from 1 to 35 (are are even large).

Is there any guide line on what could be realistic limit? The article here gives some ideas -- http://java-metrics.com/cyclomatic-complexity/cyclomatic-complexity-what-is-it-and-why-should-you-care

I am thinking of 10 as soft limit and 15 as hard limit.. Main reason is that testing gets complicated with larger values..

I would like to hear from SO community..


Solution

  • I have two methods I use:

    1. Pick a maximum value and stick to it (mine is 10).
    2. Just regularly review your code and fix the method with the highest score.

    Another method to use is to be very rigorous when fixing bugs - check back with source control to see which methods changed to fix the bug. Refactor those methods to reduce their complexity.