Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about the Style Guide  RSS feed

 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim is correct. It is not a violation of the style guide to place the semicolon directly after the plus sign.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for the response.
Matthew Phillips
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!