Code metrics is a tool which can show the developer how good is the code. Using set of measurements it will be easier to know how complex the coding is. 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.
Below list shows the code metrics results that VS calculates:
Maintainability
Index
Maintainability Index, which goes from 0 to 100 and
indicates the overall maintainability of a class, member, namespace or project.
If the value is higher than it show the code is better maintained. It also
comes up with color code for quicker view.
Green
- 20 and 100 (good).
Yellow
- 10 and 19 (moderate)
Red
- 0 and 9 (low)
Cyclomatic
Complexity
Cyclomatic Complexity tells you two important things.
First, it indicates the general complexity of a method. Lower is better; if the
number is high, the method is probably trying to cover too many different
situations and needs to be broken up into simpler, specialized methods that
cater specifically to individual situations and are much easier to maintain.
Second Cyclomatic Complexity tells you the total number of test cases you need
to write, to ensure that all possible situations have been covered. So if the
value is higher than you have to test the code with more test cases.
Depth of
Inheritance
Lower is better; if Depth of Inheritance goes higher than
three or four, your code will be difficult to maintain. The higher the number,
the more subclasses you will have to modify and it might introduce new bugs
when you do changes in base class.
Class Coupling
Lower is better; the higher the number, the more
"tied-down" a class is, with more dependencies on the rest of its
immediate environment and it will be difficult to reuse.
Lines of Code
Lines of Code (LOC) measure the size of a piece of
software by counting the total number of executable lines of code in it. Lower
is better. If you have higher value then you can go down to the function and
try to break as much as possible. It will be easier to maintain and debug.
No comments:
Post a Comment