As I was poking around, getting familiar with the refactoring book again, I
did a quick google for automatic detection of "Bad Smells" in code, and came
up with the handy, and FREE tool from compuware called Pasta.
I downloaded the 1.3Mb jar, did the usual magic invocation java -jar pasta.jar and
pointed it at some source of mine. It does a load of analysis and comes up with a rather
pretty dependancy diagram, with all the classes/methods with no dependancies of their own
at the bottom, and then other classes neatly layered on top based on their dependancies
until the top of the diagram you can see the classes with no dependant classes.
click to enlarge screenshot
If you look closer at the diagram, you can see that an 'acyclic dependancies principle' metric is
being applied at the time, which basically means if you have arrows pointing up and down the diagram
from/to any one class, then it is a bad thing. Which winds up saying my 'Cal' class smells bad.
The 'acyclic dependancies principle' or ADP is one of many metrics which you can find out more
detail of in this pdf (A bit in depth really)
I like the simplicity of Pasta, things that smell bad are coloured in red, almost identical to
the performance guides that JProbe gives me.
It then goes onto give this detail as to what offending dependancies it has, in this manner:
From "BlogState" to "Cal" |
From | To | Dependency Type | Line |
BlogState.getCalendar | Cal | return type | 131 |
BlogState.setCalendar.c | Cal | parameter type | 135 |
BlogState.calendar | Cal | field type | 185 |
|
From "Cal" to "BlogState" |
From | To | Dependency Type | Line |
Cal.setCurrentDate.state | BlogState | parameter type | 61 |
Cal.setCurrentDate.state | BlogState | parameter type | 67 |
Cal.setCurrentDate.state | BlogState | parameter type | 76 |
Cal.populateDays | BlogState.getEntries | method call | 204 |
Cal.populateDays | BlogState.getEntries | method call | 205 |
Cal.populateDays.state | BlogState | parameter type | 164 |
Not a bad tool, for a freebie, it won't refactor your code, but it will point you in some good
directions. Go on download it now, whack it over your code and see what
smells bad. I'd not see it before, and was pleasantly surprised. There is also another
tool fresh on the scene called metrics over at sourceforge, not checked it out yet...