Where Most Developers Put their Braces

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?



Blog Categories

Blog Archives

Comments

  • It depends, but never the third style

    Posted by Rubidium on 06/19/2014 10:03am

    For me it depends: I prefer compactness when possible, so I usually let them on their own lines, but for very simple properties and for one-instructions-methods I tend to write everything together on the same line. Having short properties and methods on the same line allows for fast identification of their contents without need to expand the code: if the code is collapsed, then it does something not so simple, or some comments have been added. I never use the third style because it reduces recognition of code flow branching at glance.

    Reply
  • re braces

    Posted by will on 06/01/2014 03:53pm

    no one commenting on these articles ? well after wresting what looks better many times i came to the conclusion that either is ok but i tend to have a unofficial pathology to that one liners remove the brackets simple if's with code bracket on the same if line code follows end bracket separate line same for if else if they are pretty simple and other if else dont border or lie within them ... if they do... i tend to put the brackets on a separate line for clarity

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming eSeminar to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds