• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

A style question...

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Trailboss
Posts: 23036
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
David Junta
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23036
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the first!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Junta
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!