Java tool to improve my Clean Code Development

2019-02-02 04:47发布

Are there any (static analysis / refactoring / ...) tools for Java specially tailored towards clean code development (CCD)?

I know of the usual tools for static analysis (PMD, Findbugs, Checkstyle), dependency injection, testing and code coverage. But I am looking for a tool that gives me hints how clean my code is (as described e.g. here and in Uncle Bob's Clean Code), how I can make it cleaner, preferably attuned to my clean code grade. A tool that could also show me how I am improving in CCD over time would be optimal.

An example of such a tool is CcdAddIn, which displays the CCD values according to your current CCD Grade, but its only for visual studio :(

So do you know such tools for Java? Which one is best? What of the above do they fulfill? Or do you have a reason why such a tool does not exist (yet)?


If you do not know of such a tool: Do you know of a static analysis tool that can be configured to check for the criteria given in Uncle Bob's Clean Code, e.g. warn me about smells like names or comments seeming to be chosen badly, methods that are too long or have too many parameters, and immediately suggest a particular refactoring to resolve this?

6条回答
Anthone
2楼-- · 2019-02-02 05:13

Most of the tools which detect the CCD violations work by first collecting the metrics of the code and highlight the outliers.

Sonar is one such great tool which has been already pointed out.

The below tools are specifically created as tools to collect metrics of the Object Oriented code but show violations in a graphical format which will help the developer to analyze and avoid.

iPlasma is a great tool

CodePro is an Eclipse Plugin which help in detecting code and design problems (e.g. duplicated code, classes that break encapsulation, or methods placed in a wrong class).

Relief is a tool visualizing the following parameters of Java projects:

  • size of a package, i.e. how many classes and interfaces it contains
  • the kind of item being visualized (Packages and classes are represented as boxes, interfaces and type's fields as spheres).
  • how heavy an item is being used (represented as gravity, i.e. distance of center)
  • number of dependancies (represented as depth).

Stan4j is a commercial tool that costs a couple of hundred $. It is targeting only Java projects, comes very close to (or a little better reports than? not sure) Sonar. It has a good Eclipse integration.

查看更多
3楼-- · 2019-02-02 05:14

If you are using the tremendous Hudson for continuous integration, there are a host of plugins that provide reports and trend analysis for how code is improving (or decaying ;-) ) over time. Including PMD, Checkstyle, FindBugs as well as test coverage

查看更多
Juvenile、少年°
4楼-- · 2019-02-02 05:15

For Intellij Idea users, I'd recommend the QA Plug, which is similar to Sonar. It integrates output of different tools, although it does not provide a graphical representation. It's well integrated into the IDE.

Additionally, you can use Idea's dependency analysis to detect unwanted cycles. It offers, amongst others, the Design/Dependency Structure Matrix (DSM).

查看更多
放荡不羁爱自由
5楼-- · 2019-02-02 05:16

check tool called 'checkstyle' http://sourceforge.net/projects/checkstyle/files/. U can extends the checkstyle.

查看更多
对你真心纯属浪费
6楼-- · 2019-02-02 05:19

Sonar comes preset with some decent code quality profiles--based on PMD, Checkstyle, and Findbugs--and a nice interface for customizing them for your own use. I don't think you're going to find one, universal list of "Thou shalt..." in the Java world. There are too many different applications and development approaches for that kind of uniformity. If you take a look at the predefined PMD rule sets, you'll even find a set of "Controversial Rules" which are specifically ones that tend to engender heated debates. Some love them; some hate them. So the first moral here would be to use established conventions as guidelines and add/remove as you see fit.

I've never heard of CCD in Java land, so I wouldn't expect to find a direct translation. If you care about healthy (clean?) code, you must use a tool like Sonar or else all of the tools that it compiles into one, convenient interface. Sonar does much more than just the static analysis. There's a demo instance of Sonar where you can get an idea of its features as well as recoil in horror at the metrics of some open source libraries. So the second moral would be, "Use Sonar because it's awesome."

查看更多
相关推荐>>
7楼-- · 2019-02-02 05:19

I only found the CCD Workbench, which seems to be quite close to visual studio's CcdAddIn, but I didn't find any place to download that eclipse plugin (and got no reply to my email).

The description of CCD workbench, as well as this report about designing it, are in German. Could it be that the CCD movement is stronger in Germany than in other countries? Seems to me that way.

查看更多
登录 后发表回答