Visual Studio: Code Metrics

Please see my other Miscellaneous articles.

Using Visual Studio to guide refactoring

Visual Studio provides the following powerful metrics to help guide developers as they seek opportunities for refactoring.

To begin the code metrics analyzer, r-click the project -> Analyze and Code Cleanup -> Calculate Code Metrics.

You will then be presented with a code hierarchy and scores for each level as follows.

Class CouplingLowThe greater amount of coupling or dependencies to other classes, the more difficult to test.
Cyclomatic complexityLowA high value denotes an excessive amount of return paths.
Lines of Source Code vs.
Lines of Executable Code
Narrow MarginThe greater the margin between source code and executable code, the less the Single Responsibility Principle (SRP) is being followed.
MaintainabilityHighA low index represents a higher difficulty in maintaining the level (function) during future changes – seek to decrease numerous if…else blocks, return paths, etc. Follow the Single Responsibility Principle (SRP).