You can use Sonar or IntelliJ IDEA to write better Java code. But both tools have their good and bad.
Sonar
The Good
- Macro metrics, e.g. Complexity / method, you can get a overall sense of the code quality of the whole code base
- CI integration by triggering a build failure, you can’t ignore Sonar’s opinions
- Time machine, you can see the trend over time, are we getting better or worse?
- Hot spots, it’s a good tool to analysis legacy code, you know where should you start fixing
- Visibility, everybody can see what’s going on, there is no way to hide bad code.
- Offline review, reviewer can write comments from browser.
The Bad
- The feedback is not real time, I have to wait for x minutes to get the report
- Maven, you can’t live with it can’t live without it
IntelliJ IDEA
The Good
- The feedback is real time, and in place, it’s a better way to learn programming
- You can fix violations by applying refactoring, it gives you a better alternative
The Bad
- Micro metrics only, you can get the big picture
- Programmers can ignore its warnings
- You have to use IntelliJ which you might have x reasons not to.
The Solution?
Use both.