I’ve been writing code with curly braces for a dozen years or so, starting with C++ in college, then JavaScript for many, many years, and for the last few years, C#. In all that time, I have been a fan of putting the opening curly brace on the same line as the declaration or control statement. For example:
private void DoSomething() { // ... if (somecondition) { myval = true; } // ...}
At work, though, I have been working on someone else’s code, and I always try as much as possible change my coding style to match the existing code. In this case, that means opening curly braces get their own line, like so:
private void DoSomething() { // ... if (somecondition) { myval = true; } // ...}
I find that I’m actually starting to prefer the "new line" option. But I don’t want to prefer it! I guess maybe I’m stubborn.
I agree that it is easier to visually match opening and closing braces this way, but VS2008 does that for me anyway with clever highlighting. Also, I don’t like how much extra room is taken in my editor window. I like whitespace, but this seems to put it in the wrong place for me.
Sigh. What’s a poor developer to do?
What’s your preference and why?