I've seen a number of 'code metrics' related questions on SO lately, and have to wonder what the fascination is? Here are some recent examples:
In my mind, no metric can substitute for a code review, though:
But I cannot think of a single metric that by itself always indicates 'good' or 'bad' code - there are always exceptions and reasons for things that the measurements cannot see.
Is there some magical insight to be gained from code metrics that I've overlooked? Are lazy programmers/managers looking for excuses not to read code? Are people presented with giant legacy code bases and looking for a place to start? What's going on?
Note: I have asked some of these questions on the specific threads both in answers and comments and got no replies, so I thought I should ask the community in general as perhaps I am missing something. It would be nice to run a metrics batch job and not actually have to read other people's code (or my own) ever again, I just don't think it is practical!
EDIT: I am familiar with most if not all of the metrics being discussed, I just don't see the point of them in isolation or as arbitrary standards of quality.
The answers in this thread are kind of odd as they speak of:
1/ Metrics is not for one population, but for three:
All those metrics can be watched and analyzed by all three populations of course, but each kind is designed to be better used by each specific group.
2/ Metrics, by themselves, represent a snapshot of the code, and that means... nothing!
It is the combination of those metrics, and the combinations of those different levels of analysis that may indicate a "good" or "bad" code, but more importantly, it is the trend of those metrics that is significant.
That is the repetition of those metrics what will give the real added value, as they will help the business managers/project leaders/developers to prioritize amongst the different possible code fixes
In other words, your question about the "fascination of metrics" could refer to the difference between:
So, for instance, a function with a cyclomatic complexity of 9 could be defined as "beautiful", as opposed of one long convoluted function of cyclomatic complexity of 42.
BUT, if:
one could argue:
So, to summarize:
a single metric that by itself always indicates [...]
: not much, except that the code may be more "beautiful", which in itself does not mean a lot...
Is there some magical insight to be gained from code metrics that I've overlooked?
Only the combination and trend of metrics give the real "magical insight" you are after.