Main Contents

Bad Code Metric - Crap4J

conferences, test driven development

A single number representing whether you’re six months worth of coding is actually not crap. Not code coverage, Checkstyle warnings or defects per thousand lines of code but a single score.

crap4j.png

Alberto Savio of Agitar Software presented on his new Crap4J tool at an Agile Open California session this week. Crap4J produces a single number defined by the following equation:

CRAP(m) = comp(m)^2 (1 - cov(m)/100)^3 + comp(m)
m = method
comp(m) = Cyclometric complexity of method m.
cov(m) = Test code coverage for method m.

In written terms:

Complexity bad. Tests good.

Right now there’s just an Eclipse plugin to try it out. Anything with a Crap number of 30 or above is a crappy method. And any project with more than 5% crappy methods is a crappy project. Alberto explained they wanted it to be an Agile metric so that it actually got used out there and part of that was keeping it simple. The other factor is it can easily be adjusted based on feedback and running it against many codebases.

What if you have a CRAP codebase? You can attempt to game the number to bring down the number of crappy methods. And how do you do that? You just write more tests against the high CRAP methods. And then it starts to occur to you that you could refactor as well. Gaming the system is writing tests plus refactoring. You can focus on a single number and encourage good behavior.

Ed Gibbs @ October 28, 2007

2 Comments

  1. Jeff December 12, 2007 @ 11:00 am

    Funny how the team behind C.R.A.P started thinking about the idea with the following quote:

    “We believe that software metrics, in general, are just tools. No single metric can tell the whole story; it’s just one more data point. Metrics are meant to be used by developers, not the other way around – the metric should work for you, you should not have to work for the metric. Metrics should never be an end unto themselves. Metrics are meant to help you think, not to do the thinking for you.”

    then came to the conclusion that a single number and it’s easy of consumption was more important than following their own advice.

    I would prefer a dashboard of several metrics measured over time so that the trends become obvious and those (along with some critical thinking) cause me to take action.

    Just my .02 cents.

  2. Chris July 17, 2008 @ 11:06 pm

    Don’t be so uptight guys, come on!

    CRAP4J is a very simple tool that can aid developers identify possible points of improvement without analyzing tons of data. Its very easy to use and very easy to work with especially on an agile environment.

    Guys, no tool is a silver bullet that can solve everything or give you all the information that you need. CRAP4J, like all the other tools just focused on certain aspects of software and there’s no harm in doing that.

    Cut the CRAP! :P

Leave a comment


Feed