PMD is an excellent tool for finding potential bugs and improving code quality, but it can generate a lot of false positives. Here's my list of the top 10 rules I turn off immediately, in alphabetical order, with a short comment explaining why. Descriptions for the rules can be found here.
- AtLeastOneConstructor: Why? Code is smaller without an empty, no-args contructor.
- AvoidInstantiatingObjectsInLoops: This one just seems to generate too many false positives. In addition, for short-lived objects, garbage collection is essentially free.
- CallSuperInConstructor: super() is called implicitly and requiring it just adds more lines of code.
- JUnitAssertionsShouldIncludeMessage: Most of the methods in Assert already generate good messages. I do include a message for those that don't (assertTrue(), assertFalse(), fail()).
- LocalVariableCouldBeFinal: final for variables is usually overkill and it adds line length.
- LongVariable: Clarity rules!
- MethodArgumentCouldBeFinal: Same as LocalVariableCouldBeFinal.
- OnlyOneReturn: I think it's clearer to exit early. It reduces the amount of things to think about below the exit.
- PositionLiteralsFirstInComparisons: This really isn't that bad, but myString.equals("x") just reads better than "x".equals(myString).
- ShortVariable: There are just too many cases where it's acceptable to have short variables in small methods.
- ShortMethodName: I try to make my names expressive. I've never seen this rule fire.
- SignatureDeclareThrowsException: This is an okay rule, but for JUnit tests, who cares?
No comments:
Post a Comment