Understand the complexity and maintainability of your code using Code Metrics in Visual Studio – Maintainability Index

Understand the complexity and maintainability of your code using Code Metrics in Visual Studio – Maintainability Index

Welcome back to the the 6th post in the series on understanding code complexity and maintainability.  Over the last few post we have talked about Line Of Code , Class Coupling , Depth of Inheritance  and Cyclomatic Complexity metrics. In this post we will talk about overall Maintainability Index  code metrics.  The maintainability index value measured between an index from 0 to 100. Higher values of this index indicates the better maintainability of code.

The maintainability index calculates in each and every level of code and it bubbling up to project or namespace level with an average value. This index is based on several other metrics that we have already discussed such as

Here is how this calculate :

Maintainability Index = MAX(0,(171 – 5.2 * ln(Halstead Volume) – 0.23 * (Cyclomatic Complexity) – 16.2 * ln(Lines of Code))*100 / 171)

Refer: Maintainability Index Range and Meaning

 

image

 

The Maintainability Index column also includes a set of  icons to give an overall indication of maintainability

low – Low Maintainability  –  ( When Maintainability Index within range of 0- 9)

warning – Moderate Maintainability  –  ( When Maintainability Index within range of 10- 19)

green– High Maintainability  –  ( When Maintainability Index within range of 20- 100)

Code Maintainable Index is one of the important metrics that indicates how easy to maintain your code. When you start writing code for a particular method, the maintainability index starts from 100. with the changes on the code and other metrics factor the index start decreasing

Code Health Indicator

 

Code Health Indicator – A must have visual studio extensions for all app developers

Here is one must use Visual Studio Extension that shows the maintainability index on the fly.

extensionvs

Hope this helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

6 Comments to “Understand the complexity and maintainability of your code using Code Metrics in Visual Studio – Maintainability Index”

Comments are closed.