Saturday, July 21, 2007

Eclipse's code style options are a bit messy

At work we have had an agreed upon coding style for a couple of years, but it hasn't been enforced so not everybody have followed it. When the style was established, everyone was using IntelliJ IDEA so the style was based on IDEA settings. Now it's a split between IDEA and Eclipse, so recently I was trying to create matching style settings in IDEA, Eclipse and CheckStyle -- the first two for automatic formatting and the latter for checking.

Both IDEA and Eclipse have some problems. For example Eclipse puts more whitespace in JavaDocs and I could not configure the JavaDoc formattings to be compatible so I just turned it off in IDEA. Eclipse tends to not respect the maximum line width setting for code very well -- occasionally a few characters will go beyond the limit. IDEA has the same problem for JavaDocs. Eclipse also has some problems with optimizing imports (note to self: should report /comment on bugs about those, maybe even contribute patches) that make it incompatible with IDEA.

But the biggest problem is that Eclipse doesn't have a very good user story for configuring all of this. The code formatter options (Java -> Code Style -> Formatter) are the oldest and they are pretty good -- easy to manage profiles and everything can be exported/imported. The same can be said about code clean up (Java -> Code Style -> Clean Up), but I would argue that these two separate concepts should be merged.
There is also a problem of redundancy: Java -> Editor -> Save Actions use the existing Formatter and Organize Imports settings, but they do not use the Code Clean Up settings, instead here you have to configure those again, in a non-shareable way.
However, Code Templates, Organize Imports and the general settings are worse -- they don't support different profiles, and Organize Imports does not export/import all settings (such as the number of static imports needed for .*). All of this makes it quite hard to share these settings between a team.

I think a good solution would be to replace the profiles and import/export in the different pages (formatter, clean up) with more general Code Style profiles and import/export that would cover every setting under Java -> Code Style. Then again, maybe more granular profiles are better for some reason that I fail to see, but I'm sure they could be retained somehow while solving the problem I just described.

And another idea: as Eclipse is becoming an IDE for more and more languages, and many of these language tools could possibly offer code formatters, compiler options etc., why not think of a generic code style settings UI that would be extensible by plug-ins for specific languages.


Mark Proctor said...

I'd also like to see another option for newlines in arguments. We like a newline per argument; when you have three or more arguments this is typically easier to read. However with just 2 the new line seems excessive, especially for unit testing where all the assertions have 2 arguments. So I'd like to see a "wrap after X parameters", as well as the more traditional "wrap after X cols".

Willian Mitsuda said...

Regarding the cleanup profile, see bug#178429