Sunday, 20 March 2016

PMD Coding practices - Formatting and readability



Formatting and readability - provided by PMD

Braces

IfStmtsMustUseBraces
Avoid using if statements without using braces to surround the code block.
If the code formatting or indentation is lost then it becomes difficult to separate the code beingcontrolled from the rest.

WhileLoopsMustUseBraces
Avoid using 'while' statements without using braces to surround the code block.
If the code formatting or indentation is lost then it becomes difficult to separate the code beingcontrolled from the rest.

IfElseStmtsMustUseBraces
Avoid using if..else statements without using surrounding braces.
If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.

ForLoopsMustUseBraces
Avoid using 'for' statements without using curly braces.
If the code formatting or indentation is lost then it becomes difficult to separate the code being controlled from the rest.


Java Comments

CommentRequired
Denotes whether comments are required (or unwanted) for specific language elements.

CommentSize
Determines whether the dimensions of non-header comments found are within the specified limits.

CommentContent
A rule for the politically correct... we don't want to offend anyone.


Java Logging

MoreThanOneLogger
Normally only one logger is used in each class.

LoggerIsNotStaticFinal
In most cases, the Logger reference can be declared as static and final.

SystemPrintln
References to System.(out|err).print are usually intended for debugging purposes and can remain inthe codebase even in production code.
By using a logger one can enable/disable this behaviour atwill (and by priority) and avoid clogging the Standard out log.

AvoidPrintStackTrace
Avoid printStackTrace(); use a logger call instead.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.