views:

241

answers:

4

It occurs to me (as I'm reviewing some old code) that there may be a standard way of rating code smells and I'm just not familiar with it.

To be clear: I'm familiar with a few taxonomies of code smells, what I'm looking for is a standard rating system for code smells. (Where one would be able to fairly objectively state that one piece of code smelled worse than another).

Extra points for finding an existing system that contains witty references to smelly objects.

+3  A: 

One metric can be a so called "cyclomatic complexity", which is basically a number of edges in the control graph of your subroutine (in fact it's more complex than that). It is not very reliable, but may provide a reasonable insight on how complex a method is. Other than that, I cannot think of any other numeric metric.

Anton Gogolev
+1  A: 

objectively state that one piece of code smelled worse than another

There are at least two important considerations:

  • Is this implementation buggy (does it result in unwanted functionality that's visible to the end user)?

  • Do we need to maintain it (do we currently have a mandate/need to add to and/or to edit the functionality which this code implements)?

If either and/or both of these cases then it's much 'smellier' than if not.

ChrisW
Excellent points -- thanks
Dan Esparza
+1  A: 

A good book about detecting and rating code smells is Object-Oriented Metrics in Practice: Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-Oriented Systems. The idea is to correlate some software metrics with the symptoms of a design problem. For example for detecting a God Class that class should be complex, its coherence should be low and the class should have more than few accesses to foreign data. All this attributes are transformed in software metrics.

The authors developed some tools for detecting code smells. You can check them on their website.

Ionel Bratianu
+2  A: 
Wouter van Nifterick