The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Personal preference

Posted by Hiran on November 22, 2001 at 12:44 AM

I personally prefer the first format for brace placement:


class Test {
public Test() {
}
}

Bruce Eckel's Thinking In Java, 1st Edition uses that style I believe. Also, JBuilder automatically defaults to that style of bracing when creating a new project/class. (If a project's class(es) have another style of bracing, all new classes that are created for that project are set up using the style that is used in the existing classes). I guess I see how the style where the opening brace comes on the line right after the signature is more pleasing, but I don't agree that it's easier to read. For me, it's just as easy to read the style of bracing I prefer. Also, it seems more logical to me (maybe because when I first learned Java, I used Bruce Eckel's book and thus learned it that way).
Hiran

> Hey! I originally assumed you were referring to the somewhat flawed The Elements of Java Style book (which promotes bad brace placement and gives no good reason to support that position), but I see that this Java Programming Style Guide is from JavaRanch and is a much better and rational style guide than the book (which is a bit jack-booted in its style, as it doesn't even give rationales for its edicts).

> - mfg

>
> > > i was reading an article i printed out :p
> > > check this out Java Programming Style Guide
> >

> > Of couse, keep in mind that they are only guidelines, not rules, and on some points they have made some dreadful mistakes in judgement; in particular, they encourage poor placement curly braces (based simply on historical precedent). They suggest this difficult-to-read and ugly style:
> >


> > class BadStyle {
> > void method() {
> > for( blah ) {
> > while( blah ) {
> > ...
> > }
> > }
> > }
> > }
> >

> > (a throwback to the C programming days, when cryptic code was valued, because people believed if others could not understand what they wrote, the must surely be more clever than those others) instead of this easy-to-grok and aesthetically pleasing style:
> >

> > class GoodStyle
> > {
> > void method()
> > {
> > for( blah )
> > {
> > while( blah )
> > {
> > ...
> > }
> > }
> > }
> > }
> >

> > ...not that I have any biases on the matter. This is just my completely objective assessment of the situation, of course. ;-)

> > - mfg





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us