Saturday, February 7, 2009

Verifying Compliance to Coding Standards with Checkstyle

CheckStyle is an open source tool that helps in verifying compliance to a coding standard. The rules of the coding standard can be configured in an XML file. This makes it ideal for projects that want to enforce a coding standard.

CheckStyle increases code comprehension and makes code review less taxing. It is most useful when integrated into a build process or development environment.

http://checkstyle.sourceforge.net/

Detect commonly occurring defects with PMD, Findbugs and Jlint

A compiler may have difficulty in finding some commonly occurring defects such as null assignment, empty catch block, catching the canonical Exception instead of a specific one, etc. Dr. Eric Allen lists many instances of these defects in his book ‘Java Bug Patterns’.

PMD can detect such defects in a given set of Java source file once they are described as ‘patterns’. PMD rules can be written in java.

FindBugs & JLint can detect common defects by reviewing the class files. JLint can detect inconsistencies and synchronization problems.

CPD – a variant of the PMD is used for detecting instances of code that has been copy-pasted. Duplication of code indicates non-existence of single point of control. A bug can propagate to other parts of the code if the base code contains bug in it. CPD thus can denote code that needs to be refactored.

http://pmd.sourceforge.net/
http://findbugs.sourceforge.net/
http://jlint.sourceforge.net/

These tools are very interesting and simple to use.