Code Analysis And Code Metrics
Sign in

Code Analysis and Code Metrics

In Visual Studio 2008, you can also see a new menu in the main menu named Analyze menu. There are mainly three commands: Run Code Analysis, Calculate Code Metrics and Profiling. The Code Analysis menu provides a report with the main changes to do in order to find errors and comply with best practices of the technology. The Code Metrics menu helps users find and act upon complex area of the application through metrics that are applied to your code. Let's see an example of running Code Metrics over our examples. In this report, we have some metrics such as Class Coupling, Depth in Inheritance, Cyclomatic Complexity, Lines of Code, and Maintainability Index.

Class Coupling indicates the number of dependencies between entities of your problem domain. Lower number indicates candidates for possible reuse.

Depth in Inheritance indicates the number of classes that are above in the inheritance tree from a particular class.

Cyclomatic Complexity indicates the total number of individual path through the code. It's calculated by counting the number of decision points (if, switch, do, while, foreach, for) and adding 1.

Lines of Code indicate the total number of lines of code excluding white space, comments, braces, declaration of members, types and namespaces.

Maintainability Index is an index from 0 to 100 indicating the overall maintainability of a member or a type (at assembly level,it's the total number of maintainability index of all types within it). It's calculated from other metrics such as Halstead Volume (which factors in the number and use of operands and operators), Cyclomatic Complexity and Lines of Code. Lower values indicate complex and hard to maintain. The report of this field also indicates the status with an icon.

start_blog_img