• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ Indentation Poll

Armitage

Banned
How do you indent your C++? I'm working with somebody elses code right now that's all done in a style like option 1 and I find it very hard to read - particularly when its nested.

I always use option 2 almost compulsively. I would change this code, except it makes for a huge mess when you go to look at changes in the revision control. And would likely annoy the original author if I have to send back bug fixes and such.

 
I code the same way Cooler does (though I don't see how this is limited to C++ programming :confused😉
 
The way Smilin does. The OP's options stink for me because the ending brace doesn't align with the conditional. But, sooner or later you've got to use someone else's style *shrug*.

My bigger peeve would be use of tabs, which can display and be saved differently in different text editors. Better to just use spaces and keep it consistant, though many would disagree with this too.
 
Same way that Smilin does it, though I think the GNU coding conventions recommends Cooler's way. I've never seen any of the options in the poll.
 
Originally posted by: fishbits
The way Smilin does. The OP's options stink for me because the ending brace doesn't align with the conditional. But, sooner or later you've got to use someone else's style *shrug*.

My bigger peeve would be use of tabs, which can display and be saved differently in different text editors. Better to just use spaces and keep it consistant, though many would disagree with this too.

That's an even bigger peeve - tabs. I always set my editor to insert spaces for tabs.

And yes, my poll options suck. I just put my style and the PITA style of the code I'm working with at the moment. No point in changing it now since so many have voted other though.
 
Option2 is just messed 😕

I'm option 3, of course 😛 Except when using Pascal, which has 'begin' and 'end' instead of curly braces. Then 'begin' goes on a seperate line, à la Option2. I once wrote a code style evaluator that subtracted points for methods/functions that were too long, so developers started moving the 'begin' on to the same line as the 'for' to save space. Then I had to implement a metric that dinged 'em double for trying that 😛
 
Option 3 FTW. It's clean, compact, and makes it easy to see nested structures.

Up until this year, I preferred option 4. I started using 3 a bit (group projects + Eclipse) and then got really frustrated with how much space 4 wasted, especially in simple loops/conditionals. BTW, I only used 3 for loops and conditionals. I still use 4 for classes, methods, and everything else.

How can you not like the compact elegance of:
 
wow 1 and 2 are really weird.... i'm a 3 -- was surprised to see that 3 was way more popular than 4 (i was expecting a close tie between 3 & 4).
 
Originally posted by: Cooler
Here Option that i see in one of my friends code. He was trying to be 1337
Well sure, it makes sense. If you don't have extra whitespace in your code, then the compiler can scan it faster. It then uses that extra time to perform extra optimization and that makes your final code run faster. Plus the compiler can sense how l337 you are and knows you need the extra special optimization. It's like gentoo, but for java.

I'm serious man, I've seen 5-10% improvements by writing all my code on a single line.

Edit: whoops, we're talking about c++ apparently. I've got quite a one-track mind 😕
 
Originally posted by: xtknight
Originally posted by: kamper
I'm serious man, I've seen 5-10% improvements by writing all my code on a single line.

In execution time or compile time??? Or "404 funnay not found"? 😛

white space and \n are both one char so it does not matter time wise.
He just does it so others cant read it.
 
i prefer k&r (3).. mainly because i can see more code on a page than with 4.. but 4 and 2 are by far the easiest to read.
1 is annoying.. the left brace is on a different line than the code block, but the right brace is on the same line. it's unnecessarily difficult to read.
 
Originally posted by: EpsiIon
Option 3 FTW. It's clean, compact, and makes it easy to see nested structures.

Up until this year, I preferred option 4. I started using 3 a bit (group projects + Eclipse) and then got really frustrated with how much space 4 wasted, especially in simple loops/conditionals. BTW, I only used 3 for loops and conditionals. I still use 4 for classes, methods, and everything else.

How can you not like the compact elegance of:

Yeah that's awful.

Truly guys I like the way cooler's way looks. It's very clean and compact and easy on the eye when rolling down the page. The problem is the braces don't align. If your statements get any sort of complexity to them you'll get error prone.

I don't particularly like the "look" of my way but the braces are aligned with each other and the statement itself. "My" method (I obviously didn't invent it) becomes more and more the wise choice as the code gets more and more complicated. That's my other $0.02 🙂
 
Back
Top