Where do you put your braces?

If you're writing code in a programming language derived from C (i.e. one of those with pesky curly braces), where do you like putting your braces?

Some people like putting the opening brace on a line by itself right after the declaration/statement:


I'm one of those that usually does this. It just was something I got used to from my C/C++ days and since it was the common convention in .NET back when I started fiddling around with it in 2000/2001. So this is usually what I use when coding on C#.

However, other people like to put the opening brace inline with the declaration/statement:


This question is brought to you courtesy of me noticing that IronRuby favors the "inline opening brace" style.

Actually, I use the inline-opening-brace style myself when I'm working with Java. I don't mind it, but it somehow seems wrong sometimes. I mean, using different styles when working across two languages so similar? I mean, I already have enough trouble remembering stuff like string vs. String and ToLower() vs toLowerCase() to worry about how the code looks ;-).

Historical Note: A few years back I used to be weirder and used a mixed style where I used braces-on-next-line for some things and inline-opening-brace for others depending on what it was and how many lines were in between the opening and closing braces. Yes, I was (am?) anal like that. I finally gave up on it when I grew tired of fighting the auto-formatting rules in IDEs.

What style do you favor, and why?

Technorati tags:


  1. I tend to put my braces on the same line within control statements etc. but on a separate line when writing methods/functions etc… except on my blog where I tend to compress those down to keep posts short…

  2. I like to put my braces on a new line, it gives the appearence of more readability to me, by putting a little bit of white space between your function declarations and the body of the function. Of course like all good rules, I have one exception:
    Simple property getters and setters I tend to do get { return _variable; }
    This probally stems from the fact that this is the default behavior of the prop snippet which I love so dearly!

  3. I prefer the brace on the same line style because I find that vertical space is always at a premium – I want to see more code and avoid scrolling if necessary. I’m happy that this was the default style on the DLR team when I joined.
    BTW, you can always re-jig your VS 2005+ editor settings so that CTRL-A CTRL-K CTRL-F formats your code in whatever style that you want.

  4. I like my braces on a dedicated line, it makes the code more cleaner. Sometimes when its just a single like of code, especially getter and setters, I just put them on a single line.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>