tags:

views:

1132

answers:

3

After reading the answers to the question "Calculate Code Metrics" I installed the tool SourceMonitor and calculated some metrics.

But I have no idea how to interpret them.

What's a "good" value for the metric

  • "Percent Branch Statements"
  • "Methods per Class"
  • "Average Statements per Method"
  • "Maximum Method or Function Complexity"

I found no hints in the documentation, can anybody help me?

+5  A: 

SourceMonitor is an awesome tool.

"Methods Per Class" is useful to those who wish to ensure their classes follow good OO principles (too many methods indicates that a class could be taking on more than it should).

"Average Statements per Method" is useful for a general feel of how big each method is. More useful to me is the info on the methods with too many statements (double click on the module for finer grain detail).

Function Complexity is useful for ascertaining how nasty the code is. Truly I use this info more than anything else. This is info on how complicated the nastiest function in a module is (at least according to cyclomatic complexity). If you double click on the module / file you can find out which particular method is so bad.

torial
+1  A: 

As a general rule of thumb, a cyclomatic complexity of 10 or less is where you want to be. A CC from 11 to 20 is about as high as you want to get in most cases: once you get above 20, you're more likely to encounter problems finding and fixing defects, and once you get above 50, you're usually looking at a method that needs to be refactored now.

Keep in mind that these are guidelines. It is possible to have a method with a CC of 25 that is as simplified as you can get it; you'll just want to be more careful with these methods when you need to update them.

Dave DuPlantis
A: 

As a general rule of thumb, a cyclomatic complexity of 10 or less is where you want to be.

The problem with general rules of thumb is that it encourages blind adoption across development.