• 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

Style Guide and "for each"

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
< crawling out of a hole in the earth >

I'm back . . . until the Real World intrudes again.

I've been through the Style Guide repeatedly, but I don't see how the following violates it:
 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

< crawling out of a hole in the earth >



I have to do the same also.

As far as the code, the space after the parenthesis is what stands out to me.

ie...

Check out the Style Guide 3.1.1
I do not think you'll get nitpick for using either the old or new for loops.

good luck!
gary
 
Ed Connery
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gary Ba wrote: As far as the code, the space after the parenthesis is what stands out to me.
Check out the Style Guide 3.1.1
I do not think you'll get nitpick for using either the old or new for loops.


Hmm...I've been consistent in that style since Java-1b. I believe that Katrina told me that it was OK to use or not use the space after the parenthesis (though not before).
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did your nitpicker change? Other than that I am not sure.
Sorry

gary
 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After glancing over the style log, I would remove the spaces after and before the parenthesis, and have a look at the : separating the contents of the for loop.
for (String s : nameList) looks wrong to me. All 'for' statements I've ever seen use a different syntax. Also, in the style guide there is no space before the separator, but there must be one after. Look up 'for' loops and see if that helps. Here's a link I found while checking for myself: for loops
 
Ed Connery
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carol Murphy wrote:
for (String s : nameList) looks wrong to me. All 'for' statements I've ever seen use a different syntax. Also, in the style guide there is no space before the separator, but there must be one after.


That's the "for each" loop introduced in JDK 1.5. I used the syntax found in Just Java 2 (6th Ed.) and in Core Java (8th Ed.) The style guide doesn't address the "for each" loop yet, but it's a very compact and readable tool when iterating over an entire array.
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about the late reply -- in the middle of a move here, and my internet connection is quite unstable.

The spacing is fine, as long as you are consistent.

You can say

int age = 8 ;
or
int age = 8;

Also with respects to parentheses, we're fine with
( this )
or
(this)

but not
( this) or (this )

you do have to pick one style and stick with it.

I'm guessing the nitpick about the for each loop is that we still haven't converted to using 1.5, and the for each loop won't compile as 1.4.

Yeah, I know -- we really need to get on with the conversion, but it's just not happened yet.
 
reply
    Bookmark Topic Watch Topic
  • New Topic