File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Style Guide Question

 
Tommy Leak
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic