Calculate Code Metrics - Way to assert your code

Calculate Code Metrics:

Whenever we write any code, we will refactor and optimize the code for better performance. Really we cannot assert our code is optimized or not, since we just did what we know about code metrics.  Visual Studio provides an option to assert our code metrics. In Solution explorer, right click on solution or project file gives you the “Calculate Code Metrics” option.  You can check and refactor your code by using this option.

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.
  1. 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.
  2. 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 will require more tests to achieve good code coverage and will be less maintainable.
  3. Depth of Inheritance: Indicates the number of class definitions that extend to the root of the class hierarchy. The deeper the hierarchy the more difficult it might be to understand where particular methods and fields are defined or/and redefined.
  4. 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.
  5. Lines of Code: Indicates the approximate number of lines in the code. The count is based on the IL code and is therefore not the exact number of lines in the source code file. A very high count might indicate that a type or method is trying to do too much work and should be split up. It might also indicate that the type or method might be hard to maintain.

Comments

  1. Can you provide more detailed explanations with images....

    ReplyDelete

Post a Comment

Popular posts from this blog

BDD - Acceptance Test Driven Development

Angular JS – Part 2

.Net Collections