SONAR Eclipse / PMD
- Setup SonarQube or SonarSource locally.
- Run analysis after changes.
- Remember / know all the rules.
- Knowing rules helps avoiding them.
- Most common MAJOR violation.
- Hard to fix once introduced
- How to calculate? Count +1 for each of the constructs below:
- If / Else If / Else - every conditional within +1
- Switch – Case - +1 for each case
- For / for each / do..while / while - +1 for each loop
- Return – if there is more than one return, +1 starting at the second.
Avoid Cyclomatic Complexity
- Can't see everything in 1024 X 768 - Time for new method.
- How to write behavior / methods?
- List all behavior.
- Determine specificity (related / common behavior).
- Most specific become methods.
- Unit tests are now concise and specific.
Clean Up Command
- Use Clean Up Command – Fix common violations
- Hidden Field
- Integer Instantiation
- Loose coupling
- Unused private method
- Visibility Modifier
- Unused Imports
- If Stmts Must Use Braces
- If Else Stmts Must Use Braces
Code Style / Formatter
- Use code templates
- Auto eliminate documentation violations.
- Let IDE do the skunk work.
- Focus on logic and public API documentation.
- Use code formatter to improve readibility.
Code Style / Quick Assist
- Use Quick Assist religiously
- Use method before definition
- Use split declarations, rename
- Define constants.
- Code Recommenders - efficient searches.
- Eclipse Luna (4.4+) - Split pane for efficient coding.
Install Kewl Plugins
- Make your life interesting.
- Interesting life means better code.
- Eclipse Color Theme - Indigo & Helios
- IDE Themes - > Eclipse Juno
- Roll your own.