Tuesday, September 29, 2009

Find My Bugs

Update: Added new distribution for JUnit lab.
No matter how much preparation or thinking you've done, programming almost never really goes smoothly. It surprises me when something I wrote doesn't crash and burn on the first try, because I expect there to be something wrong. Rarely am I surprised when I see the words "NullPointerException" on my screen. And it's usually small mistakes that I'm sure thousands upon thousands of programmers have made before me.
One of the things that amaze me about Java is the variety of libraries and tools that are out there. Tools like Checkstyle, PMD, and Findbugs are unique to Java as far as I know. And I've found them to be useful too. PMD and Findbugs can catch most of those silly errors that every programmer makes. And if we were working on a larger project, those silly errors become much harder to track down. And I can see the use of Checkstyle for enforcing style and documentation in large projects. For small projects and assignments where the code size is small, it's a little harder to see the use.
The thing about these automated QA tools is that people tend not to use them if it's not easy for them to do so. I've been using the Eclipse IDE for so long that I don't even remember what the proper invocation is to compile all of my Java sources on the command line. And invoking the above tools via the command line would be a pain. Fortunately, we have build systems that help make these things easier. While we'd use Make in most cases, Apache Ant seems to be the most recommended system for Java programming. Ant also has support for all of our QA tools, making it much easier for us to use.
So after learning about build systems and automated QA in class, we applied them to our little Robocode robots. For the most part, I feel that I am a stickler for style. However, Checkstyle caught an instance where I missed a space in an if statement and where I didn't end a Javadoc sentence with a period. I also neglected to put a package.html file, which I imagine most of the students in the class also forgot to do. PMD caught a statement in my Robot class where I had done "if (x != y) {...} else {...}" when I should've made it more clear. Findbugs had no issues with my code. So my issues were pretty much documentation and readability issues. Again, for a small project like ours, it is a bit of an annoyance. But for a larger project, I can definitely see the importance if others will be looking and/or using our code.

How do you like my style? Not so much I guess.

Okay, that is a bit confusing.

We used the Ant files provided to us by Philip's DaCruzer Robot distribution. Thank goodness too, because putting these Ant files together must be a lot of work. Fortunately, they're generic enough to be applied to any Java project as long as the proper entries are edited and/or removed. After I had edited the Ant files, it was rather easy for me to run the tools on my robot and make them eventually pass "ant -f verify.build.xml", which runs all of the tools and fails if any of the tools report issues. So we've gotten our crash course in build systems and automated QA. Now it's time for testing!
You can download my Menehune distribution here.

No comments:

Post a Comment