Quick notes on code style

Lovely, the code is rolling in. I synced, and have been making a few
updates here and there to style. Here are some notes on code style
which I'd like to put up for discussion upfront.


First, the most controversial one. I like to use "final" everywhere. I
find it worth the hit on readability to catch unintentional reuse of
variables, prevent undesired inheritance, etc. If there are no
significant objections, I'd like to humor my habit and use final where
possible. I'll be adding it later anyway.

I go for full words for identifiers:
Writer writer = ...;
instead of
Writer w = ...;

I spell out all imports instead of using the * syntax. I suppose it's
a little annoying if you're not using an IDE but IDEs do it
automatically and this has always been the coding standard I've seen.
It's useful to spell out all the dependencies.

No System.out or System.err except in main() methods. Everything else
should be handled with logging or an exception.

"&" and "|" work as logical boolean operators in Java too, but they
are the non-short-circuit sort. "&&" and "||" are almost always what
you want.

I use the Sun brace style:
if (x) {
  ...
} else if (y) {
  ...
}
and use them on one line conditions too:
if (x) {
  ...
}

Primitives and corresponding classes (e.g. int / Integer) become a bit
interchangeable in Java 5 but it's still worth keeping them straight.
In this line:
final Integer l = theBody == null ? 0 : theBody.length();
you want an int:
final int l = theBody == null ? 0 : theBody.length();

Received on Friday, 25 May 2007 00:48:58 UTC