Code metrics values
Code metrics values
The increased complexity of modern software applications also increases the difficulty of making the code reliable and maintainable. Code metrics is a set of software measures that provide developers better insight into the code they are developing. By taking advantage of code metrics, developers can understand which types and/or methods should be reworked or more thoroughly tested. Development teams can identify potential risks, understand the current state of a project, and track progress during software development.
Developers can use Visual Studio to generate code metrics data that measure the complexity and maintainability of their managed code. Code metrics data can be generated for an entire solution or a single project.
For information about how to generate code metrics data in Visual Studio, see How to: Generate code metrics data.
Software measurements
The following list shows the code metrics results that Visual Studio calculates:
-
Maintainability Index - Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability. Color coded ratings can be used to quickly identify trouble spots in your code. A green rating is between 20 and 100 and indicates that the code has good maintainability. A yellow rating is between 10 and 19 and indicates that the code is moderately maintainable. A red rating is a rating between 0 and 9 and indicates low maintainability. For more information, see the Maintainability index range and meaning blog post.
-
Cyclomatic Complexity - Measures the structural complexity of the code. It is created by calculating the number of different code paths in the flow of the program. A program that has complex control flow requires more tests to achieve good code coverage and is less maintainable. For more information, see the Wikipedia entry for cyclomatic complexity.
-
Depth of Inheritance - Indicates the number of different classes that inherit from one another, all the way back to the base class. Depth of Inheritance is similar to class coupling in that a change in a base class can affect any of its inherited classes. The higher this number, the deeper the inheritance and the higher the potential for base class modifications to result in a breaking change. For Depth of Inheritance, a low value is good and a high value is bad.
-
Class Coupling - Measures the coupling to unique classes through parameters, local variables, return types, method calls, generic or template instantiations, base classes, interface implementations, fields defined on external types, and attribute decoration. Good software design dictates that types and methods should have high cohesion and low coupling. High coupling indicates a design that is difficult to reuse and maintain because of its many interdependencies on other types. For more information, see the Class coupling blog post.
-
Lines of Source code - Indicates the exact number of source code lines that are present in your source file, including blank lines. This metric is available starting in Visual Studio 2019 version 16.4 and Microsoft.CodeAnalysis.Metrics (2.9.5).
-
Lines of Executable code - Indicates the approximate number of executable code lines or operations. This is a count of number of operations in executable code. This metric is available starting in Visual Studio 2019 version 16.4 and Microsoft.CodeAnalysis.Metics (2.9.5). The value is typically a close match to the previous metric, Lines of Code, which is the MSIL-instruction-based metric used in legacy mode.
Anonymous methods
An anonymous method is just a method that has no name. Anonymous methods are most frequently used to pass a code block as a delegate parameter. Code metrics results for an anonymous method that's declared in a member, such as a method or accessor, are associated with the member that declares the method. They are not associated with the member that calls the method.
Generated code
Some software tools and compilers generate code that is added to a project and that the project developer either does not see or should not change. Mostly, Code Metrics ignores generated code when it calculates the metrics values. This enables the metrics values to reflect what the developer can see and change.
Code generated for Windows Forms is not ignored, because it is code that the developer can see and change.
Next steps
相关文章
- Entity Framework Code First关系映射约定
- PHP 代码简洁之道 ( PHP Clean Code)(第二部分)
- Code Complete-13/7/23
- [MEAN Stack] Go thought -- code
- python code practice(二):KMP算法、二分搜索的实现、哈希表
- [Tools] Scroll, Zoom, and Highlight code in a mdx-deck slide presentation with Code Surfer <🏄/>
- 数据库内核月报 - 2015 / 06-MySQL · 答疑解惑 · binlog event 中的 error code
- inconsistent debug frame and source code -Eclipse调试器里看到的代码行数和实际源代码不一致该怎么办
- Visual Studio Code 保存代码时报Applying code action Organize Imports
- Command PhaseScriptExecution failed with a nonzero exit code
- 【报错】table burner has no column named USER (code 1): , while compiling: INSERT INTO burner(USER,YELL
- Ubuntu 下Unable to install “Visual Studio Code“:snap “code“ has “install-snap“ change in progress
- Mac ERROR:root:code for hash md5 was not found.
- msm8610 lcd driver code analysis
- 使用SVN clang: error: linker command failed with exit code 1 (use -v to see invocation)
- 安装visual studio code(VS Code)并修改为中文
- MAT 启动错误解决方案 Java was started but returned exit code=13