Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding code metrics

I recently installed the Eclipse Metrics Plugin and have exported the data for one of our projects.

It's all very good having these nice graphs but I'd really like to understand more in depth what they all mean. The definitions of the metrics only go so far to telling you what it really means.

Does anyone know of any good resources, books, websites, etc, that can help me better understand what all the data means and give an understanding of how to improve the code where necessary?

I'm interested in things like Efferent Coupling, and Cyclomatic Complexity, etc, rather than lines of code or lines per method.

like image 234
Feet Avatar asked Sep 30 '08 23:09

Feet


People also ask

What are code metrics?

Code metrics is a set of software measures that provide developers better insight into the code they are developing.

How do you check code metrics?

“Code Metrics is a tool which analyzes our project, measures the complexity and provides us better insight into the code.” To generate code metrics for our project, we can go to Analyze Menu –> Calculate Code Metrics.

What are metrics of code quality?

Code quality metrics are a number of variables used to measure and determine if code is of high quality. Teams can then use those metrics for code review for changes, test coverage, and other actionable insights. Variables such as code complexity, portability, security, clarity, reusability, and others.

Are code metrics useful?

In this paper, with the help of bivariate and multivariate regression analysis, we show that code metrics are indeed good maintenance predictors, even when their relations with size are neutralized.


2 Answers

I don't think that code metrics (sometimes referred to as software metrics) provide valuable data in terms of where you can improve.

With code metrics it is sort of nice to see how much code you write in an hour etc., but beyond they tell you nada about the quality of the code written, its documentation and code coverage. They are pretty much a week attempt to measure where you cannot really measure.

Code metrics also discriminate the programmers who solve the harder problems because they obviously managed to code less. Yet they solved the hard issues and a junior programmer whipping out lots of crap code looks good.

Another example for using metrics is the very popular Ohloh. They employ metrics to put a price tag on an opensource project (using number of lines, etc.), which in itself is an attempt which is flawed as hell - as you can imagine.

Having said all that the Wikipedia entry provides some overall insight on the topic, sorry to not answer your question in a more supportive way with a really great website or book, but I bet you got the drift that I am not a huge fan. :)

Something to employ to help you improve would be continuous integration and adhering to some sort of standard when it comes to code, documentation and so on. That is how you can improve. Metrics are just eye candy for meetings - "look we coded that much already".

Update

Ok, well my point being efferent coupling or even cyclomatic complexity can indicate something is wrong - it doesn't have to be wrong though. It can be an indicator to refactor a class but there is no rule of thumb that tells you when.

IMHO a rule such as 500+ lines of code, refactor or the DRY principal are more applicable in most cases. Sometimes it's as simple as that.

I give you that much that since cyclomatic complexity is graphed into a flow chart, it can be an eye opener. But again, use carefully.

like image 103
Till Avatar answered Sep 23 '22 04:09

Till


In my opinion metrics are an excellent way to find pain points in your codebase. They are very useful also to show your manager why you should spend time improving it.

This is a post I wrote about it: http://blog.jorgef.net/2011/12/metrics-in-brownfield-applications.html

I hope it helps

like image 22
Jorge Fioranelli Avatar answered Sep 21 '22 04:09

Jorge Fioranelli