Code Metrics in VS 2008
I am not sure whether you have tried the Code Metrics tool in VS 2008. It is a very handy tool and simply answers the question "How difficult is your code to maintain?"
You need to know how to interpret different code metrics to take corrective actions:
Maintainability Index — Should be high as possible. 100 is the target you want to achieve. This index is an aggregate of all the code metrics indexes (code complexity, lines of code, inheritance depth and class coupling)
Cyclomatic Complexity — Number of branches your code takes (switch, case, if statements). You want to keep this number low.
Depth of Inheritance — Inheritance chain. You want to keep this value as low as possible. Every time you inherit, the value goes up by 1. You want to avoid the bad cascading effect (Poorly designed class will cause the entire inheritance chain difficult to maintain)
Class coupling — this shows the dependency between different class types. If this number is higher, it means your code will become difficult to maintain. Just imagine you had numerous classes calling each other methods without any discipline.
Lines of Code — Keep a tab on the number of lines of code you have to write. With the advancement of tools and technologies, people are moving towards lesser number of codes. Keep in mind the line of code does not include the number of lines used for attribute definition, comments declaration and constructs.
There is no hard and fast rule on what the code metrics index value should be. Your project can be complex and the index numbers could be high.
An insight into code metrics will help you identify the problem areas and help you refactor code if needed.