This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Style Guide and Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Style Guide and "for each"" Watch "Style Guide and "for each"" New topic
Author

Style Guide and "for each"

Ed Connery
Ranch Hand

Joined: Mar 11, 2010
Posts: 70
< 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:
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

< 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


star chaser..
Ed Connery
Ranch Hand

Joined: Mar 11, 2010
Posts: 70
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

Joined: Oct 23, 2009
Posts: 161

Did your nitpicker change? Other than that I am not sure.
Sorry

gary
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
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

Joined: Mar 11, 2010
Posts: 70
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.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Style Guide and "for each"