aspose file tools*
The moose likes Cattle Drive and the fly likes Style Guide Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Style Guide Question" Watch "Style Guide Question" New topic
Author

Style Guide Question

Tommy Leak
Greenhorn

Joined: Mar 10, 2005
Posts: 3
I question about a part of the instructors solution and the style guide. Forgive me, I don't want to come across as "nitpicking" because I certainly know that is not my job. However, I do want to come across as someone who earnestly wants to learn and improve. The command

System.out.println("usage: Hundred SomeName");

Should this not be written as:

System.out.println( "usage: Hundred SomeName" ) ;

The difference being the spacing before and after the quotes and before the semi-colon. I looked at the examples in the style guide and I see it being demonstrated both ways. Is one more correct than the other or are they both OK?
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Originally posted by Tommy Leak:
I question about a part of the instructors solution and the style guide. The command

System.out.println("usage: Hundred SomeName");

Should this not be written as:

System.out.println( "usage: Hundred SomeName" ) ;

The difference being the spacing before and after the quotes and before the semi-colon. I looked at the examples in the style guide and I see it being demonstrated both ways. Is one more correct than the other or are they both OK?

Somebody correct me if I'm wrong, but I believe the "most" correct way to write this line would be:
System.out.println( "usage: Hundred SomeName" );
My rationale is that only implicit casts omit the spaces inside the opening and closing parentheses, and a space is only required between an identifier and a semi-colon. ( I think, anyway! )
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
In terms of the style guide, there is no difference between the two versions. The guide only gives a rule requiring space around identifiers (with certain exceptions). If the thing you're considering putting spaces around is not an identifier, then spaces are entirely optional. I asked Paul about this long ago, thinking that it was an unintentional oversight. But no, apparently this ambiguity is intentional. Or at least, not considered worthwhile to resolve. It's unclear why it's important to isolate identifiers with space (except when it's not), but non-identifiers to not require such protection. Apparently "some utilities" behave differently for identifiers than for other things. I've no idea what these utilities are, or why anyone in his right mind would want to use them in the 21st century. (Or even the last few years of the twentieth...) Anyway, regardless of my views of the merits of the style guide, the fact is that as far as the original question is concerned, the style guide does not favor either style over the other.


"I'm not back." - Bill Harding, Twister
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Jim sez If the thing you're considering putting spaces around is not an identifier, then spaces are entirely optional.

So, might the next question be what's an identifier and what's not? I'm guessing that this may be the point of confusion, mostly because I tripped over it myself way back when.

As a fresh-baked newbie I didn't really get what was meant by 'identifier'; it was a term I hadn't seen used outside the Drive. Terms like variable name, method name or class name were certainly more common. Now that I think of it, I still haven't seen 'identifier' much since, now that I'm a less fresh newbie . As a nitpicker, I think I've seen others deal with it as I did initially too: stick spaces in all over the place.
[ April 07, 2005: Message edited by: Pauline McNamara ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
I think Peter van der Linden uses the word "identifier". For example, he wrote, "Keywords are reserved words, and they cannot be used as identifiers."

As Pauline said, "variable name, method [/b]name[/b] or class name" are each a type of identifier.

As Jim said, the rule is "spacing around all identifiers". This includes spacing between identifiers and punctuation (like a semicolon). However, spacing between a quote mark and a semicolon is not required.


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: Style Guide Question