Friday, March 11, 2011

Sunday, November 25, 2007

Static Code Analysis

Static code analysis is a powerful tool for identifying problems in source code, problems like unused variables, incorrect use of static variables, overly nested code, etc. I use Eclipse for the most part these days, so I decided to investigate which tools work better for me with Eclipse.

1. Eclipse SDK

The Eclipse Java perspective itself is very good in this area. The default set is good, and it finds problems as it goes. The only thing I don't like is that the "fix problems like this" feature does not work. Maybe in 3.3.... The configurability is excellent too, with the ability to set flagging at the error, warning, or "none" levels, either on a per-project or per-workspace level.

2. FindBugs

Findbugs is nice too. The integration with Eclipse has been thoughtfully done. The problems show up in the same place that the ones that Eclipse itself does. Also, the default set of problems found are all things I agree with. As a test, I set it loose on the SaTScan code I've been working on, and it found 4 problems, all of which I agree with. For example, the pattern "this.getClass().getResource" is a bad one, because sub-classes will get "unexpected behavior"

3. Lint4J

Lint. The granddaddy of them all. Lint4J is a worthy Java version. It finds a different set of potential problems than FindBugs does. It has the same strenghts that FindBugs does, in that it is conservative, and integrated with the Eclipse "problems" mechanism. It's flaw is that it is maybe too conservative. I find this one mostly useful when cleaning up some "foriegn" code.

4. PMD

This one has a special place in my heart because I contributed to it some years ago (the Beans rules). However, I don't think I'll be using this one in Eclise too much. Why? First of all, it finds WAY TOO MANY problems. With the default set, the SaTScan code that FindBugs found 4 problems in, and Lint4J none, PMD found 68. That's in 229 lines of code, including white space and curly brases. Too many.... Even the line "public static void main(String[] args) {" got flagged, because I was not using the "args" variable. I'm sure with some effort I could configure it to do something I liked, but who has time? Also, the Eclipse integration uses its own perspecive. It's kind of cool, but in practice, it's disruptive. The first rule for a plug-in "don't get in my way!" I noted that the Eclipse plug-in was done by someone other than the PMD author. PMD has the most potential for fine control over coding practices, it might be good in some corporate shop where uniform code quality is important, maybe with selected rules integrated into the build process.

GeoViz Toolkit Links

There are plans to use the GeoViz Toolkit in GEOG 486: Cartography and Visualization course here at Dutton. Adrienne Gruver is going to supply me with some data, and we will cut a special edition of the GeoViz Toolkit with that data in it.

The most stable current build is available from http://www.geovista.psu.edu/grants/cdcesda/software/

The API Docs are available from: http://hudson.geog.psu.edu/job/GeoViz%20Toolkit/javadoc/

Previous binary versions are available from: http://hudson.geog.psu.edu/job/GeoViz%20Toolkit%20Java%201.5/

Previous source versions are in the repository, hosted by Google: http://code.google.com/p/geoviz/

I am working on getting three seperate things strapped together: the codebase repository, the continous integration (CI) server, and the executable program. So far, the CI server listens to the codebase no problem, but I still need to write a script to get the executable application publishing correctly.

The GeoViz toolkit is a project derived from the GeoVISTA Studio project.

Eclipse Europa -- I love you

I just updated from Eclipse 3.2 to 3.3, so I thought I would share how it went.

I has a bit of trepidation, because I use Eclipse every day. So, I unzipped the download into a new folder, and fired that up, then tested the 3.2 version. They coexist happily! So, that's a good start. Next, I tried to get my favorite plug-ins. Findbugs -- OK. JLint -- negatory! It seems that JLint is down for a while. Sadness. Subclipse -- OK. So, far, we have lost one thing I like, so it's not looking good.

Time for a little bug smashing. I had 232 warnings listed in the "Problems" tab. Lots of them are for unused imports. I pick one, get the quick fix suggestion, and then ask Eclipse to fix the rest. It works... oh my... this is great. Now I love love love Europa! JLint -- we hardly knew ye. One note -- I need more unit tests in the codebase. You could really do a lot of damage with these auto-fixes -- I may have done so by removing unused local variables. Sometimes crappy coders (like me in days of yore) would have important work done as a side effect of a method call which assigns a value to a local variable.

Quick note on the spell checker -- it's kind of hard to see how to invoke the suggested replacements. Ctrl + 1 is the secret handshake.

-Frank