| Author |
Question about the Style Guide
|
Matthew Phillips
Ranch Hand
Joined: Mar 09, 2001
Posts: 2676
|
|
In the style guide it states that post increment operators should be formatted as follows: i++ ; I am just curious about the reasoning behind this. Would someone please explain? Matthew Phillips
|
Matthew Phillips
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
|
|
Well, the main point of the item about post-increment operator spacing is that there should not be a space between the identifier and the operator - this is just tradition, as we're all so used to seeing this without a space that it would annoy a lot of us to see it otherwise. If you're asking why is there a space between the operator and the semicolon, that part isn't actually required. In Coop style you see a lot of semicolons with spaces in front of them because they come after identifiers, and Coop style requires space around identifiers except for the exceptions noted. Of course ++ and -- aren't actually identifiers, so no space is actually required between ++ and ;, or -- and ;. But if you want to put one there you're welcome to do so, simply because the Coop tends to put in a lot of extra spaces anyway in places normal people would never put them.  So: <code><pre>i ++; // bad i++; // good i ++ ; // bad i++ ; // good</pre></code> [This message has been edited by Jim Yingst (edited March 16, 2001).]
|
"I'm not back." - Bill Harding, Twister
|
 |
Matthew Phillips
Ranch Hand
Joined: Mar 09, 2001
Posts: 2676
|
|
The reason I was curious was that I was nitpicked for not putting the space there. I agree with the reasoning for making people stick to the style guide for the Cattle Drive, but I am going to question everything I don't understand since that will insure that I learn it. Matthew Phillips
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
|
|
|
If you got nitpicked for writing "i++;" rather than "i++ ;", I have no idea why. A plus sign certainly isn't an identifier.
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9001
|
|
Jim is correct. It is not a violation of the style guide to place the semicolon directly after the plus sign.
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Matthew Phillips
Ranch Hand
Joined: Mar 09, 2001
Posts: 2676
|
|
Thank you all for the response. Matthew Phillips
|
 |
 |
|
|
subject: Question about the Style Guide
|
|
|