[Mono-dev] Coding guidelines confusion on braces
Jonathan Pryor
jonpryor at vt.edu
Mon May 26 18:06:29 EDT 2008
On Mon, 2008-05-26 at 19:48 +0200, Gert Driesen wrote:
> Can someone clear up the confusion on whether braces should be on the same
> line as the class/namespace declaration, or on the next line?
This is unofficial (as you're right, the published Coding Guidelines are
vague on this point), but I believe that any construct that can be used
with generic types should place the '{' on a newline, and anything that
can't be used with generics should use the same line.
So `namespace' would always have '{' on the same line:
namespace Foo {
while class, struct, and method declarations would use a new line. The
reason for this is that it makes for consistency when using type
parameter constraints:
class Bar <T> : BaseClass, IComparable<Bar<T>>
where T : IComparable<T>
{
...
Otherwise, you have an inconsistency (some classes have '{' on the same
line, some don't) or you have ridiculously long class declarations as
you place every `where' clause on the same line (which I've never seen
anyone do, and makes for unreadable code once you have more than one
type parameter).
This also dovetails nicely with our guidelines for properties, loops,
exception blocks, etc., as these constructs can't be generic and thus
should use the same line.
What would also be nice is for the Guidelines to concretely address the
location of braces on "chained" tokens, e.g. this:
if (foo) {
}
else {
}
or this:
if (foo) {
} else {
}
The same would logically go for try/catch/finally, do/while, etc.
I prefer the former, though I've seen plenty of both styles running
around.
- Jon
More information about the Mono-devel-list
mailing list