VirtualMock's Approach to Code Quality

VirtualMock strives to have a clean and high-quality codebase. Several tools are used to achieve this goal. PMD and Checkstyle are used to ensure good style. Clover and Hansel are used to ensure full unit test coverage.

It is always pleasantly surprising when a "secondary goal" such as good style or complete unit test coverage uncovers a bug, or leads you to a better design that you would not have thought of otherwise. This has happened several times on VirtualMock :)

Checkstyle Rule Changes

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. Virtualmock uses a Checkstyle config that is based on the default Sun checks config. Changes that have been made are detailed below. You can see the Checkstyle report for VirtualMock. See Checkstyle Project Page on SourceForge for more info on Checkstyle.

Changes to 'Javadoc' checks

JavadocMethod - This check has the "allowUndeclaredRTE" property set to "true". I prefer to not declare RuntimeExceptions.

JavadocVariable - This check has the "scope" property set to "package", because Javadoc is not provided for all private fields.

Changes to 'Size Violations' checks

LineLength - Changed to 90. Jalopy sometimes lets a line run a bit over 80 chars.

Changes to 'Coding Problems' checks

HiddenField - This check has the "ignoreConstructorParameter" and "ignoreSetter" properties set to true, to allow "this.field = this" to be used in setter accessors.

MagicNumber - This check has "3" added to the list on the "ignoreNumbers" property. "3" is used in some hardcoded array indices in VirtualMock.

Changes to 'Class Design' checks

DesignForExtension - This check was disabled. VirtualMock is designed for flexibility, and as the description of this rule on the Checkstyle site states, this approach limits flexibility of subclasses.

Changes to 'Miscellaneous' checks

GenericIllegalRegexp - The default check warns if there are any trailing spaces before a newline, using pattern "\s$". This was changed to warn if there is more than one trailing space, using pattern "\s{2}$". This was done because Jalopy automatically puts a trailing space after asterisks on empty javadoc lines.

FinalParameters - This check was disabled. IMHO, putting final before every parameter would add sacrifice more in readability than it would gain in stability. Plus, I think other tools (such as PMD) can catch if you modify a parameter.

PMD Rule Changes

PMD scans Java source code and looks for potential problems. This section details the changes that have been made to the default PMD rule sets. You can see the PMD report for VirtualMock. See PMD Project Page on SourceForge for more info on PMD.

Changes to 'controversial' rule set

OnlyOneReturn - This rule (which I used to follow) was disabled. VirtualMock is written in Java, not COBOL (no offense, I've written plenty of COBOL :) ). Arguments against this approach are mentioned in Martin Fowler's Refactoring book, I believe in the discussion of Guard Clauses.

AtLeastOneConstructor - This rule was disabled. What's wrong with using the default constructor?

Changes to 'design' rule set

ConstructorCallsOverridableMethod - This rule was disabled. VirtualMock does this to provide a design that is well-factored as well as extensible. If a subclass causes problems, then it can solve them :)

Changes to 'naming' rule set

LongVariable - Changed maximum variable length from 12 characters to 50 characters. There's no such thing as a variable name that is too descriptive :)