2

I downloaded the "Microsoft CodeLens Code Health Indicator" VS 2013 extension ( http://visualstudiogallery.msdn.microsoft.com/f85a7ab9-b4c2-436c-a6e5-0f06e0bac16d)

...and opened a simple utility. The score of my methods ran from a low of 52 to a high of 92.

The Microsoft-written method was the only one with a higher score.

1 reference | maintainability 94
public Form1()
{
    InitializeComponent();
}

Commenting out "InitializeComponent();" raised the maintainability to the max (100), but of course, in this case at least, the ultimate in maintainability is also the negative ultimate in usability.

Is there any way to get a score of 100 on useful code?

UPDATE

Here's some code ranked 100% maintainable:

enter image description here

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Maintainable code has a lot to do with how your business rules change over time. Adding more abstractions can make it much easier to deal with the changes. But as the application indicates, the only truly maintenance free method is one that doesn't do anything. – crthompson Sep 24 '13 at 16:10

2 Answers2

5

According to Microsoft's Dev Network, that maintainability reading is rated on a scale of:

  • 20-100 - Maintainable
  • 10-20 - "Warning zone"
  • 0-10 - Unmaintainable code

Having code within the 90's is already very good code, I believe if you are at 100 then you aren't really working with anything.

As far as "Can you have usable code" with 100, I would say no initially, but I suppose it could be possible that something useful could exist.

http://msdn.microsoft.com/en-us/library/bb385914.aspx

Rogue
  • 11,105
  • 5
  • 45
  • 71
2

This blog post details the formula's used in the Maintainability index. The formula is:

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

So yes it seems the way to get the highest index (100) for a method is to have no code in it. The usefulness of metrics like these is not the high-end numbers, it is in the low-end numbers. You look at the worst parts of your code and make sure they are acceptable. It's a waste of time to look at methods in the 90's and try to push them to 100. FWIW, a low-end of 52 is seems pretty good.

Mike Zboray
  • 39,828
  • 3
  • 90
  • 122
  • And actually, the 52 was a legacy method; I refactored it to make it, I believed, much more grokkable, and yet even my refactored method was only 55. So: beauty/maintainability is in the i of the bee holder. – B. Clay Shannon-B. Crow Raven Sep 24 '13 at 16:32