• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A style question...

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the first!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It means our mission is in jeapordy! Quick, read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic