Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Question about the Style Guide

 
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
 
Wanderer
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
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.
 
Sheriff
Posts: 9099
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
 
Hold that thought. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!