Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usual values on Code Metrics (C#, Visual Studio) for production projects

There are some questions on Code Metrics here, especially this one on goal values. What I'm looking for though is what's "usual" on real life production projects. Maybe it's just me, but no project I ever get put on ever has these things in mind so when I run ReSharper Code Issues or Visual Studio Code Metrics it seems I'm the first one - so the values always surprise me.

Examples from my current SharePoint assignment:

Maintainability | Cyclomatic cmplx. | Inher. depth | Class coupl. | LOC
67              | 6,712             | 7            | 569          | 21,649
68              | 3,192             | 7            | 442          | 11,873

So, the question is, what values do you usually see "in the wild"? Optimal values and best-practice aside, what values are normally encountered?

like image 205
John-Philip Avatar asked Mar 26 '12 13:03

John-Philip


1 Answers

I assume these values stated are on an assembly level. If so, Cyclomatic Complexity and Lines of Code are most helpful on the method level. Inheritance depth should be looked at on the class level primarily. Class coupling gives more useful feedback when looking first on the method level and then on the class level.

In addition to the guidelines providing in the stack overflow link you included, Code Complete 2nd Edition has this to say about method Cyclomatic Complexity, page 458:

  • 0-5 The routine is probably fine.
  • 6-10 Start to think about ways to simplify the routine.
  • 10+ Break part of the routine into a second routine and call it from the first routine

In "real life" projects, what is acceptable probably will depend on the type of development process you are using. If the team is practicing TDD (test-driven-development) and strives to write SOLID code, then these metrics should be near optimal values.

If TAD (test-after development) or, even more so, code without unit tests, then expect all the metrics to be higher than optimal as the likelihood of having more coupling, more complex methods and classes, and perhaps more prolific inheritance may be elevated. Still, the goal should be to limit the cases of having "bad" metrics, regardless of how the code has been developed.

like image 78
Matt Avatar answered Oct 22 '22 04:10

Matt