Code formatting

Stefan Negrea snegrea at redhat.com
Wed Apr 4 13:49:31 UTC 2012



----- Original Message -----
> From: "John Mazzitelli" <jmazzite at redhat.com>
> To: rhq-devel at lists.fedorahosted.org
> Sent: Wednesday, April 4, 2012 8:20:08 AM
> Subject: Re: Code formatting
> 
> On Wed, 2012-04-04 at 10:39 +0200, Heiko W.Rupp wrote:
> > While I am not a big fan of our code formatting conventions of
> > 
> > public some long signature that
> >    wraps in the second line {
> >    here thestatements begin without a space
> > 
> > Can we please adhere to our freaking conventions? Perhaps change
> > them slightly
> > to make the above case look like:
> > 
> > public some long signature that
> >    wraps in the second line
> > {
> >    here thestatements begin and you can even see it
> > 
> 
> That was EXACTLY how I liked it - but years ago I was overruled
> because
> "we aren't doing it like the rest of the Java community". I always
> wanted the { to be on its own line, but no one voted for my way :)


The typical Java coding standard has { at the end of the code line. I've seen { on a new line mostly in .Net (C#). I've never seen a standard that uses both ways with some logic to choose between the two. I've noticed that Eclipse can handle such formatting rules but it is clearly not default.

My personal preference is to always have { at the end of the code line. It's a wasted character anyway (I love python syntax) so using one more line to single it out makes the code too long (I like terse, compact code). I do like } to be on a new line to avoid clobbering the previous code line.


Here are two examples (GWT and Infinispan) consistently using { at the end of the line irrespective of wrapping:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java
https://raw.github.com/infinispan/infinispan/master/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java





> If we are to do this - it would involve reformatting the entire code
> base - not a call that is easy to make.
> 
> How about another problem I've been seeing - the ordering of the
> import
> statements. IIRC, we should be doing it alphabetically - but I don't
> think we ever standardized on where to put import static statements -
> it
> looks like intellij puts them up top and eclipse after the regular
> imports (or maybe its vice versa? in either case, I know some people
> do
> it one way, and others the other way).
> 
> > I think for XML we never had the convention of using an indent of 2
> > spaces.
> > It is fine with me, but then lets all do it.
> 
> I don't think we ever standardized this - but I think we've been
> doing 3
> for the most part. I don't think we do 2 (unless you are looking at
> the
> pom.xml files - in which case, ANYTHING goes, we've never been
> careful
> as a team to format them the same).
> 
> > Also in Java we seem to randomly use 3 and 4 spaces; the JBoss
> > guidelines
> > use 3 spaces, so should we
> > 
> 
> We should NOT be randomly doing this - our standard has been 4 spaces
> for a very long time - years in fact. I don't recall seeing any code
> that was indented only 3 spaces, unless you are looking at very old
> code
> that hasn't changed in a long time.
> 
> _______________________________________________
> rhq-devel mailing list
> rhq-devel at lists.fedorahosted.org
> https://fedorahosted.org/mailman/listinfo/rhq-devel
> 


More information about the rhq-devel mailing list