0

We have a number of issues that PMD has identified for us - a lot of which seems nit picky. I have a list below - may I ask the hive mind - if you had to pick the top 5 crticial rules out of below list what would they be? I am trying to balance effort with criticality of what would be bad if it made to production.

Thanks in advance!

AssignmentInOperand

AvoidDeeplyNestedIfStmts

AvoidDuplicateLiterals

AvoidInstantiatingObjectsInLoops

ClassWithOnlyPrivateConstructorsShouldBeFinal

CollapsibleIfStatements

CyclomaticComplexity

EmptyIfStmt

ExcessiveMethodLength

ExcessivePublicCount

ImmutableField

InefficientStringBuffering

InsufficientStringBufferDeclaration

LocalVariableCouldBeFinal

LooseCoupling

MethodArgumentCouldBeFinal

NcssMethodCount

NPathComplexity

PackageCase

PositionLiteralsFirstInComparisons

SignatureDeclareThrowsException

SingularField

TooManyFields

UncommentedEmptyConstructor

UncommentedEmptyMethod

UnusedImports

UnusedPrivateField

UseSingleton

4

3 回答 3

1

Yikes! One could argue that all of these point to a code base that really needs refactoring to improve reusability and future maintainability, and none of them are "nitpicky". Keep in mind that static analysis is making recommendations, and that you're the best judge of what's good for your code, your customers, and your budget.

But if I had to pick a few to focus on first, I'd go after those that indicate deeper architectural problems: AvoidDeeplyNestedIfStmts, CyclomaticComplexity, LooseCoupling, TooManyFields, and ExcessiveMethodLength. Just my $0.02...

于 2013-08-22T16:55:53.853 回答
0

PMD or any other static code analyzer helps you to write better code. There are certain parameters/rules against which your code is analyzed. Anything critical will be catch by java compiler itself. These tools simply helps you to find few flaws in your code and format your code in a cleaner way.

于 2013-08-22T16:47:35.103 回答
0

The more of these you fix, the better and cleaner your code will be. If you think a rule is too "nitpicky", and you don't want it to be reported by PMD, then remove the rule from your rules.xml file. PMD also allows you to place comments in your code to ignore that one occurrance.

于 2013-08-22T16:52:34.467 回答