File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ranch Office and the fly likes A style question... 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 » This Site » Ranch Office
Bookmark "A style question..." Watch "A style question..." New topic
Author

A style question...

David Junta
Ranch Hand

Joined: Dec 10, 2000
Posts: 86
On the style.jsp page, you imply (by example) that we should use curly braces like this:
void foo()
{
while ( bar > 0 )
{
System.out.println();
bar-- ;
But in your applet code, you put the opening curly brace on the same line as the class declaration or the while statement.
Are both ok?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20498
    ∞

We do not have the applet source code. It was lost.
To work on the version 2 of the applet, we had to reverse compile the applet. The reverse compiler I used generated the brace placement "the right way".


permaculture Wood Burning Stoves 2.0 - 4-DVD set
David Junta
Ranch Hand

Joined: Dec 10, 2000
Posts: 86
Sorry, but I'm still confused.
Is this right?
-----------------------
void foo()
{
while ( bar > 0 )
{
System.out.println();
-----------------------
Or is this right?
-----------------------
void foo(){
while ( bar > 0 ) {
System.out.println();
-----------------------
Or are both ok?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20498
    ∞

the first!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I think that when David said "your applet code", he meant one of the examlpes of code for applets in the Code Barn (or somewhere else?). When Paul read "applet code" he thought of the code for "the" applet at JavaRanch, the Rules Round-Up. So that's why these conversation fragments didnt' match up.


"I'm not back." - Bill Harding, Twister
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Just to clarify: both are OK. In fact:
public void foobar() {
is much more universally used. Look in almost any Java book and you will find the braces laid out that way.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
David Junta
Ranch Hand

Joined: Dec 10, 2000
Posts: 86
Thanks, Jim. You're right that my confusion was caused by the fact that I did indeed mean one of the applet examples in the Code Barn, which used a different style from the one Paul has on the style.jsp page. As Thomas points out, I've seen curly braces used almost exclusively the way I saw it in the HelloAnimThreadFirst Applet code in the Code Barn:
public void foobar() {
My point wasn't to quibble about which way is best...but rather to learn which way or ways were "acceptable" at JavaRanch. I love the site so far (my second day) and plan to continue using it regularly to learn java. Thanks, DJ
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I agree that it is confusing that all of the code in the Code Barn doesn't match what is stated in the Style Guide. We're working to correct that ASAP.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A style question...
 
Similar Threads
Doubt in Nested Inner Class
WA #1.....word association
can't be resolved to a type error
Local variable
do while and while