W3C home > Mailing lists > Public > public-mobileok-checker@w3.org > May 2007

RE: Quick notes on code style

From: Jo Rabin <jrabin@mtld.mobi>
Date: Fri, 25 May 2007 09:35:06 +0100
Message-ID: <C8FFD98530207F40BD8D2CAD608B50B4336076@mtldsvr01.DotMobi.local>
To: <public-mobileok-checker@w3.org>

Reading this is a bit like watching a medical programme on TV - where
you think you've got all the symptoms. Wait! I do have all the symptoms
- if there is a Java solecism to commit, I'll commit it!

I'll try harder in future, but dread to think what you'll make of the
next lot of changes :-(

Jo

> -----Original Message-----
> From: public-mobileok-checker-request@w3.org [mailto:public-mobileok-
> checker-request@w3.org] On Behalf Of Sean Owen
> Sent: 25 May 2007 01:49
> To: public-mobileok-checker@w3.org
> Subject: 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 08:35:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:13:03 GMT