I’ve tried a bunch of style checkers over the years like PMD, Checkstyle, Jalopy, JTest, etc in the hopes that they would find bugs and improve code. Ultimately, I have always ended up uninstalling every style checker I’ve ever used. I have eventually decided that they are not worthwhile or at least not cost effective (in terms of time).
My general thoughts on where they fall down:
- Overload – there are a zillion rules and often most of them are totally useless to me. Sometimes they are even contradictory, so you are guaranteed a warning whether you write something one way or another.
- Configuration – going through the zillion rules can be time consuming at best and maddening at worst. The configuration aspects are improving over the years but it is still usually a pain. If you also factor in getting consensus on which rules to use in a development organization, the pain is magnified.
- Integration – I use Eclipse for dev and Ant for builds. All of the main style checkers integrate with an Eclipse plugin and Ant tasks but usually these plugins seem fairly shoddy. Little thought is given to how using a style checker integrates with my daily work, particularly my daily work on a real source code base with >1 million lines of code. Meanwhile, Eclipse itself is improving constantly and adding more and more of the style / bug checks that I actually care about to it’s built-in behavior.
- Benefits – after giving the checkers an honest try for a while I have to ask myself whether the code is indeed better and I can’t honestly say that it is enough better to be worth everything above. After thinking a lot about why I even look at style checkers my primary goal is to find bugs. My experience has been that style checkers rarely find actual bugs in the code. As I said above, there are a few obvious types of things that are easy to check for statically (like variables that are unused or written but not read) and the leading IDEs are quickly providing more and more of that subset of style checking that I find useful.
I have had some luck with programs that do byte code analysis or simulation. In particular, I have used FindBugs off and on over the years and it has found actual bugs in the code and things that could become bugs if not fixed, so it scores high in that regard. Unfortunately, the configuration and integration aspects of FindBugs are really poor so it has not become a part of my daily work. Rather, I periodically download the newest version and run it a few times to check code. I have integrated into our build process in the past but it generally has not been worth the time it takes to run on a daily basis. I’ll continue monitoring it as it matures.</ol>