How to interpret code metrics (calculated by SourceMonitor)

Thomas Koschel picture Thomas Koschel · Sep 25, 2008 · Viewed 10.8k times · Source

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?

Answer

torial picture torial · Sep 25, 2008

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.