Adds extra space to the beginning of each block (without just being an empty line). Occasionally I'll add a newline to one of the closing braces (to show the difference between the last if in a loop and the end of a loop, for example) but normally I find it looks just fine like above.

[EDIT: Heh, didn't realize that this was my first post. I swear I had posted before.... This thread didn't have any replies when I first posted, so my post was made without any of the information in the replies. I'm of the camp "it doesn't matter, just be consistent (and don't use GNU style)".]

[EDIT 2: OH! The thread I posted in was moved into the religious wars whitespace/braces thread. That makes a lot more sense.]

I like vertical alignment because it makes it so you can see the stack. Also what about when you just put a { without a control structure before it? Like if you're in straight-C and want to make a temporary variable. WHAT THEN?

Just want to say that I've used Whitesmiths simply because that was the style I was taught in. I went to a summer camp where the programming was taught in MicroWorlds, and the instructor did all of his stuff in that style, so that's what I use.

I use what the wiki article (http://en.wikipedia.org/wiki/Indent_style) refers to as "Compact Control Readability style", though I had never heard it called that until today. Basically it's just a slightly modified Java style where else statements do not go on the same line as the closing brace of the preceding if. Wikipedia says:

This style makes it easy to skim the left edge of the code for control statements (whereas styles like 1TBS make statements such as "else" harder to see because they are after an end bracket on the same line). However it keeps the code more compact than styles like the Allman style, by putting opening brackets at the end of lines (as opposed to on their own lines).

I used to be an Allman guy, but I've basically switched to something like that compact style. There are a couple exceptions: I don't usually put the opening brace of a function on the same line as the signature, and if the control statement itself is multi-line, then the brace gets its own line (personally I think you're insane if you don't do this). Thus:

I used to be an Allman guy, but I've basically switched to something like that compact style. There are a couple exceptions: I don't usually put the opening brace of a function on the same line as the signature, and if the control statement itself is multi-line, then the brace gets its own line (personally I think you're insane if you don't do this).

You think I'm insane then... I usually just leave a blank line after the control statement in that case, like so:

That's pretty reasonable... the point is just to clearly delineate the loop header or condition from the block that it surrounds. Especially with 4-space indents (the one true amount ) they can really blend together:

Oh, and in the rare case of opening a block of code that isn't the body of an if or loop, then putting the opening brace on a line by itself is about the only reasonable choice. (You might do this if you want to limit the scope of a variable -- particularly in C++, to get the destructor to run at a given time.)

EvanED wrote:That's pretty reasonable... the point is just to clearly delineate the loop header or condition from the block that it surrounds. Especially with 4-space indents (the one true amount ) they can really blend together:

Oh, and in the rare case of opening a block of code that isn't the body of an if or loop, then putting the opening brace on a line by itself is about the only reasonable choice. (You might do this if you want to limit the scope of a variable -- particularly in C++, to get the destructor to run at a given time.)

You can do a one tab indent for the body and two for the continued part of the control statement in that case, but it still looks better with one tab each in allman.

Nah, I'm actually about the same, with a couple specific exceptions like the "loop header continuing to a second or subsequent line" than I mentioned above (where putting the { on a separate line really does help).

Nah, I'm actually about the same, with a couple specific exceptions like the "loop header continuing to a second or subsequent line" than I mentioned above (where putting the { on a separate line really does help).

There are certainly things that make code unreadable that I'm not really okay with, but in general I haven't really come across those things.

Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.

sourmìlk wrote:I don't actually care. I haven't really come across any commonly used style that I find unreadable.

I don't really find any unreadable either, but there is a convenience factor in having code spaced out how you like it.

I use K&R style and while I find others readable, I find "line for the open braces" styles wasteful of screen space and "open brace left of code" styles a bit inconvenient for editing. Also, I do find K&R-like styles the most readable, although it's not a huge thing (it's also nice that K&R-style code looks a lot like Python layout).

Another thing is that I think differences between styles are ameliorated by syntax highlighting. If I had to read monochrome code a lot, I'd be a lot more fussy about style.

EvanED wrote:Nah, I'm actually about the same, with a couple specific exceptions like the "loop header continuing to a second or subsequent line" than I mentioned above (where putting the { on a separate line really does help).

Maybe I should start doing this. I hate those multiline loop conditions (sometimes I even define booleans just to get rid of them).

There's only one proper way to format code, and it's more or less secret. This is because the illuminati don't want the hoi polloi to gain the awesomeness that such formatting entails. But now, you can dominate your machine with this one weird trick!

if (something){ do this thing; while (not done yet) { drum your fingers; sit by a lake; } do one last thing;}else{ if (this happened) { do something odd; do something even; } else { go for a walk; }}

This has all the advantages of the aligned braces, and collapses useless spaces so that you can see more on the screen at once. Clearly there's no better way.

Jose

Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

This is basically what I normally use. But I dont much care what others use, its all cool. <SNIP>

Me too. I didn't even know it had a name till I saw this topic (Whitesmith? Sounds cool!). It's very clear, concise and logical, even though it tends to take up a lot of vertical space (all those lines with just one symbol... if I had to print it, I would probably sink into a depression about dead trees and stuff).

I must also mention that I generally write short and relatively complicated programs so this style helps my dyslexia A LOT.

Yakk wrote:Sometimes, you just don't want to burn vertical space on else.

As far as I'm concerned, it's really the closing brace that's wasting space. The word "else" is actually meaningful and deserves to begin a line.

Partly. The closing brace matches the prefix of the block by its indentation (assuming that the OTS indents the statements inside a block and not the block itself), so you can quickly see where the block ends.That said, I do like Python's indent-instead-of-brace style. (not that I ever used Python. Haskell instead)

Flumble wrote:The closing brace matches the prefix of the block by its indentation (assuming that the OTS indents the statements inside a block and not the block itself), so you can quickly see where the block ends.

Sure, but the word "else" also tells you that the if-block is over. I like Python a lot, including its syntax, but you don't actually need anything that radical for the case of an if/else. There are languges that have a syntax along the lines of:

I use 1TBS or "the one true brace style", but with attached function braces. It is a variant of K&R. But you always add curly braces even around single statements. Basically allowing safe line insertion anywhere in the file.

Hammer wrote:For myself, I like Allman. However, my main requirement for style is that, whatever you decide to do, do it consistently! I regularly get handed code from beginners whose reaction to suggestions to maintain a consistent style is "Do I haaaaave to?" Then, after listening to them whine, I get to plow through code that uses three different indenting styles selected at random when they bother to indent at all. Grrrrrrrrr...

That smells like someone is copy-pasting for many different places instead of doing their own stuff... not that there is anything wrong with that, code posted on the wild is meant to be copied, and why should I reinvent the wheel?, BUT not even caring about reformatting it means usually they didn't even care to read and understand the code. When I copy code I always read it to try to understand how it works and always reformat it on my own style while i read it, and usually change the variable names if I don't like them.