Information Technology Reference
In-Depth Information
one-character variable names. By default, PMD's scanning lengths are
set to 3; however, teams can modify these values for longer names if
desired.
PMD can also facilitate the simplification of code. For example,
the method shown in Listing 7-4, while syntactically correct, is rather
verbose.
LISTING 7-4
Completely Legal Code, but Rather Verbose
public boolean validateAddress(){
if(this.getToAddress() != null){
return true;
}else{
return false;
}
}
Once this method is flagged by PMD, it can be made more
straightforward, as shown in Listing 7-5.
A Simplified Method, Thanks to PMD
LISTING 7-5
public boolean validateAddress(){
return (this.getToAddress() != null);
}
PMD can be run via Ant or Maven and, like most every other
inspection tool on the market, PMD produces an XML report that can
be transformed into HTML. For example, the report in Figure 7-4 dis-
plays the violations for a series of .java files in a code base.
As mentioned earlier, PMD can also report complexity metrics like
cyclomatic complexity, long methods, and long classes. Checkstyle is
another open source tool available to Java developers, and it has exten-
sive documentation and Ant and Maven runners capable of producing
HTML reports. FxCop is a similar tool for the .NET platform with
myriad rules and reporting capabilities. PyLint is available for Python.
By continuously monitoring and auditing code, your team can stay
on track with architectural and coding guidelines. Issues are identified
early and often , thus avoiding any long-term maintenance issues.
Search WWH ::




Custom Search