Where Most Developers Put their Braces

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

When creating blocs, where do you put the squiggly braces in your code? It isn’t a question with an answer that will cause programs to run faster or developers to be more efficient, but it is a question that can cause a huge amount of debate among developers. Where do you put your braces when you are creating blocks of code? With over 1200 responses, we now have the winning answer!

There are generally three styles that come up when people where to put braces. The first style is to put them on their own line:

Braces Belong on Their Own Line

The first of four options we gave in asking where brace go is to put them on their own lines:

A Block
{
    // Stuff
}

Braces Belong ont eh Same Line as the Rest of Code

The second style puts the opening and closing braces on the same line as other code:

A Block {     /* Stuff */ }

The Opening Brace Should be with Other Code. Closing Brace Should be on Own Line

And, the third style puts them all on the same line

A Block {
    // Stuff
}

No Need for Braces

Of course, we also tossed out the option in our survey for people to say they don’t use braces.

The Results of Brace Usage

The end results are shown in the following graph. With over half the votes, most developers believe braces belong on their own lines. Second with nearly a third of the votes was to put the opening brace on the opening line of code, but keep the closing brace on its own line.

Where Most Developers Put their Braces

Of course, if you split out the votes from those that took the poll on Codeguru from those that were on VBForums, the results change a slight bit. The order stays the same; however, on Codeguru the winning area goes up to 61% whereas on VBForums, it drops a little to 50%.

Did the winning style of using them on their own lines match what you do?

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read