[Mono-list] Re: [Mono-devel-list] mono style guidelines

Jonathan Gilbert 2a5gjx302@sneakemail.com
Tue, 09 Mar 2004 02:02:20


Am I the only person who finds it utterly displeasurable to look at code
which is not consistent in where it places its braces? I personally have a
rule that I always put the close bracket in either the same row or the same
column as the open bracket. This leads to code like this:

public int Property { get { return _property; } set { _property = value; } }

or

public int Property
{
  get { return _property; }
  set { _property = value; }
}

or

public int Property
{
  get
  {
    return _property;
  }
  set
  {
    _property = value;
  }
}

I have noticed that a large number of other people like to put the opening
braces on the same line:

public int Property {
  get {
    return _property;
  }
  set {
    _property = value;
  }
}

I've also seen people stack up close braces:

public int Property {
  get {
    return _property;
  }
  set {
    _property = value;
} }

I have asked people why they do it this way and have received two
explanations:

1. "It makes it easier to see where the block starts." I don't quite follow
this one, but if it really makes it easier for them, then fine.
2. "It uses fewer lines in a printout." This one is most often heard at
Universities where they like to pretend they are old-fashioned and use text
printouts of assignments in order to mark. Code where '{' constitutes half
of the lines DOES use more pages and splits functions across page
boundaries more. In this context, even I will acquiesce and do what I can
to minimize the wastage of vertical space (while keeping my code readable
of course).

This all said, I am willing to read code written in either my style or the
open-brace-on-same-line style, but it seems counter-intuitive and downright
ugly, at least to me, to use a different standard for different parts of
the code. It looks disorganized. It does not look intentional. It looks to
me as though the person writing the code couldn't be bothered to care about
the placement of open braces.

Anyway, to close off this rant, I'll just note that it would be trivial
enough to hack up a tool to rearrange the code changing ONLY the position
of {'s in order to suit the reader, and as such I don't see this particular
aspect of code style as being of ultimate importance, despite the widely
distributed nature of mono's development. This is just my take on it :-)

Jonathan

P.S. As for broken line indentation, I would like to join a previous writer
in stressing the importance of getting the tabs and spaces in the right
order! If you choose to use tabs to indent the main body of code, fine, but
when you have a broken line, indent with spaces after you reach the current
tab indent point!

<tab><tab>public void function_with_lots_of_args(int a, int b, int c, int
d, int e, int f,
<tab><tab>                                       int g, int h, int i, int j)
<tab><tab>{
<tab><tab><tab>...

..not that I use tabs either :-) I'm a 2-space kind of guy.

At 11:50 AM 07/03/2004 -0500, you wrote:
>Hello,
>
>> The ECMA docs seem to use
>> 
>> class Foo
>> {
>>     public int Bar() {
>>     }
>> }
>> 
>> but most of the C# code done on VS.NET has
>> 
>> class Foo
>> {
>>     public int Bar()
>>     {
>>     }
>> }
>
>We use the later as well:
>
>class Foo {
>	public int Bar ()
>	{
>	}
>
>	public int Property {
>		get {
>			return 1;
>		}
>	}
>}
>
>Notice that this is different from what Ben posted.