J
Jean Lutrin
Our project leader is making the decision to enforce coding standards
through the use of our IDE. While standards and consistency are
beneficial, I'm unhappy with one limitation of our IDE (IntelliJ IDEA
4.5), namely its inability to preserve extra spaces. I've found that
a judicious use of spacing can often make code much easier to read and
consequently to understand. Below is an example of before and after
formatting. For me, the formatted code seems to blur together and is
much harder to read. I'm wondering what opinions others might have.
I agree with you that extra spaces can make code much, much
more pleasant to use.
Moreover, the preferred presentation of a source code file to a
programmer should /really/ be a detail. Only the structure is
important.
But I've got good you can both accomodate your boss's
will and have your extra spaces... If your willing to
do some extra work.
This can be done under IntelliJ. I work mostly with
IntelliJ but it should work under Eclipse and other IDEs too
(and, for sure, it is doable under *the* editor, (x)emacs
At first, I decided that I would conform to the "standard", whatever
that is, and modify my coding style to match the one you get when
you do, under IntelliJ, "Tools / Reformat code" (using the default
settings).
But then I did indeed find it sometimes very annoying. So I wrote
my own plugin for IntelliJ (it's not hard), to do some
extra "beautifying" (it's basically "Tools / Reformat code" + some
eye candy for arrays and alignment).
What do you mean when you say that IntelliJ is unable to
preserve extra spaces ? Do you mean that Tools / Reformat code
removes what it considers unnecessary spacing ?
Now, if your boss is concerned about you conforming to the
standard, do the following :
1. Use the normal "Tools / Reformat code" before commiting
to the CVS (or whatever code repository you use)
2. Call your plugin to "beautify" your code when you get back
some source file from the CVS that doesn't look good to you.
Note that you can still compare your source file with those
in the CVS: IntelliJ has an option to "ignore extra spaces"
when comparing a source file with one from the CVS.
The only issue is that IntelliJ has a very convenient way
of displaying which lines were modified and which were not
at the left of each line and when you do your own reformatting,
it shows every line reformatted as "modified" (but when using
the "CVS / Compare with..." there's no problem). For me it's
no a problem though: I /mostly/ adhere to the standard, besides
for some occasionnal small arrays and alignment in some very
precise cases). Now maybe there's an option somewhere in
IntelliJ to fix this behavior!?
/sorry about that not-so-clear paragraph/
IntelliJ's so called "Open API" to write plugins is not
that "open" but it's open enough and there are enough examples
and open plugins, available with source code, that should
get you started.
I've written two "plugins" for IntelliJ so far: one that
"beautifies" the code by inserting extra spaces to suit
my taste and one other that adds and remove automagically
System.out's (for quick and dirty debugging, when I don't
feel like doing the "clean" log4j logging). The latter allows
me to add System.out that gets automatically removed by
a single shortcut (say, before committing), so nobody sees
that I, temporarly, added quick and dirty System.out's.
Same for the "extra spaces beautifier".
I developed these plugins at home and nobody's gonna notice
that little 20 Kb jar file in your IntelliJ/plugins directory.
My plugins are ugly hacks (so ugly that I would be ashamed
to show you the sourcecode), but you can find several source
code for IntelliJ plugins at www.intellij.org
This is not yet a real "source code in database" (scid) that
some other languages / IDEs have, but with my little IntelliJ
plugin and the CVS, I'm getting closer to that...
Do a groups.google.com search on "source code in database" and
have fun
See you,
Jean