Use Visual Studio's "code metric value" to improve code quality, Visual Studio

Source: Internet
Author: User

Use Visual Studio's "code metric value" to improve code quality, Visual Studio
1. software metric value index 1.1 Maintainability Index

Indicates the maintainability of the source code. The higher the value, the better the maintainability. The value ranges from 0 to 100. The green rating ranges from 20 to 100, indicating that the Code has a high degree of maintainability; the yellow rating ranges from 10 to 19, indicating that the code is moderately maintainable; the red rating ranges from 0 to 9, indicates low maintainability.

1.2 lap complexity

It is created by calculating the number of different code paths in a program stream to indicate the complexity of a program. Programs with complex control flows require more tests to achieve good code coverage and are not easy to maintain.

In the following two cases, 1 is added to the computation cycle complexity:

  • Branch (if, while, do)
  • Case statement in switch

For example:

// Lap complexity 1 public void Method () {Console. WriteLine ("Hello World! ");} // Lap complexity 3 public void Method (bool condition1, bool condition2) {if (condition1 | condition2) {Console. WriteLine (" Hello World! ") ;}// Lap complexity 8 public void Method (DayOfWeek day) {switch (day) {case DayOfWeek. Monday: Console. WriteLine (" Today is Monday! "); Break; case DayOfWeek. Tuesday: Console. WriteLine (" Today is Tuesday! "); Break; case DayOfWeek. Wednesday: Console. WriteLine (" Today is Wednesday! "); Break; case DayOfWeek. Thursday: Console. WriteLine (" Today is Thursday! "); Break; case DayOfWeek. Friday: Console. WriteLine (" Today is Friday! "); Break; case DayOfWeek. Saturday: Console. WriteLine (" Today is Saturday! "); Break; case DayOfWeek. Sunday: Console. WriteLine (" Today is Sunday! "); Break ;}}

 

1.3 inheritance depth

The inheritance depth of computing in the inheritance hierarchy. The deeper the hierarchy in the inheritance tree, the more complex class development, testing, and maintenance, because the deeper the hierarchy, it is more difficult to understand the definition and (or) redefinition of specific methods and fields.

1.4 category Coupling

Class coupling is a measurement of how a class is connected or dependent on another class. A good practice is to always implement less dependent classes or low-level coupling.

1.5 lines of code

Indicates the number of lines of code. The count is based on the IL code, so it is not the exact number of lines in the source code file. A very high count may indicate a type or method that tries to do too much work and should be separated. It may also indicate that the type or method may be difficult to maintain.

2. Calculate the code measurement value Step 01. Run "Calculate the code measurement value"

Step 02 View "code measurement result"

Step 03 use "code metric result"

Filter:

Export:

 

Column management:

Calculate the code metric value:

 

Reference: https://www.codeguru.com/csharp/csharp/cs_network/improving-code-quality-with-visual-studio-code-metrics.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.