xboard-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XBoard-devel] coding style


From: Arun Persaud
Subject: Re: [XBoard-devel] coding style
Date: Tue, 03 Jan 2012 14:58:11 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0

Hi

On 01/03/2012 02:21 PM, h.g. muller wrote:
> 
>> Guess this is a matter of taste... to me having those extra lines makes
>> it a lot more readable than the other version... mostly because I find
>> it easier to see where the block starts and ends by having the {} in the
>> same column...
> 
> Well, that can be achieved without uing extra lines by writing the
> openig brace
> on the same line as the firststatement (and closing braces on the same
> line as
> a following else). Like
> 
> if(A)
> {   x = 1;
>     y = 2;
> } else
> {   x = 2;
>     y = 1;
> }
> 
> This is actually the style I used in my own programs.

I also find it easier to have the extra new line...

if (A)
  {
    x=1;
    y=2;
  }
else
  {
    x=2;
    y=1;
  }

makes it much easier for me to see where the "else" part starts in this
example... I also find that using extra newlines helps making things
more readable, I don't quite see why you want to have as much as you can
in one line... AFAIK on most monitors you should be able to see enough
lines of code to figure out what you are looking at with the GNU coding
style...

Anyway, it seems we are all more or less on the same page... the only
issue that I can see is, if wa want to write

if .... {
  foo
}

or

if ...
  {
    foo
  }

which seems to be only a difference of 1 newline/block, which I think is
not a big difference and I would lean towards the GNU coding style on
this one.

Here is again the code example from the GNU manual:

if (x < foo (y, z))
  haha = bar[4] + 5;
else
  {
    while (z)
      {
        haha += foo (z, z);
        z--;
      }
    return ++x + bar ();
  }

my summary would be: no {} for one liners in if, everywhere else {} on
their own line, indent level 2 whitespaces, plus the comments in
http://www.gnu.org/prep/standards/standards.html#Syntactic-Conventions

Is everyone OK with this?

Arun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]