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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With