This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes new style/standards document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "new style/standards document" Watch "new style/standards document" New topic
Author

new style/standards document

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20496
    ∞

I've updated the style sheet. Before I make a link to it, I would appreciate some feedback. Check out www.eporkchop.com/style.html


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Pawel Veselov
Ranch Hand

Joined: Jan 14, 1999
Posts: 165
A quick note.
Sun's JAVA code convention wants figure brackets to be put on the same line with the block originator, i.e.
void method() {
// body
}
is preferred over
void method()
{
// body
}
related documents:
http://www.sun.com/workshop/java/wp-coding/
http://java.sun.com/docs/codeconv/html/CodeConventionsTOC.doc.html

------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )


With best of best regards, Pawel S. Veselov ( aka Black Angel )
Matt Midcap
Sheriff

Joined: Jan 07, 1999
Posts: 440
I like it. My comments:
I didn't see much on using logic (or I missed it). For example, I think it is always better to use "positive" logic than "negative" logic. i.e.
<pre>
while( number == 0 )
{
do something ;
}
</pre>
Instead of:
<pre>
while( number != 1 )
{
do something ;
}
</pre>
As a newbie, it keeps thing CLEAR as to what is really happening.
Also, I've heard that some people like to put native "private" data types at the end of a class. Reason: someone looking at the code doesn't need to know about it.
Is this correct or (like everything else) personal preferance? I tend to want to know about what I'm looking for right from the top.
Thanks for the insight on some standards, it helps.
Matt


Best Regards,<br />Matt Midcap
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Pawel: This is a big can of worms. I tend to side with Paul, as do most Java and/or C/C++ programmers I happen to know, but I'm always open to reasoned argument. I find the fact that the "{" can't easily be visually matched with the "}" a big hindrance to reading "Sun" style code. Can you give me any actual advantages of this layout over the layout Paul recommends?
Matt: I think this habit is a left-over from some coding suggestions for C++, where the interface for a class is in a "header" file and the implementation is in a different file. In this case, it might make sense for a reader of the header file not to need to know about private members - only a reader of the implementation file would need to know.
In Java, however, there is no such distinction. Any reader or maintainer of a source file needs to see the whole thing, and any style guidelines should suggest a layout which promotes maximum understanding as the file is read through. Personally, I generally prefer to read "bottom-up", so that I am happy with what all the parts do before I consider the whole. For this reason, I tend to prefer the class layout which Paul recommends.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20496
    ∞

Thanks Frank. You covered it so well I have nothing to say!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: new style/standards document
 
Similar Threads
Hungarian notation
problematic method call
new java college - need feedback
loops
Java College