[phobos] phobos commit, revision 2098

Steve Schveighoffer schveiguy at yahoo.com
Tue Jan 4 10:57:12 PST 2011





----- Original Message ----
> From: spir <denis.spir at gmail.com>

> But braces on their own line is simply weird and too much  a demand for my 
>taste. I cannot guess any rational advantage; do you really  find
> 
>     if (cond)
>      {
>         this();
>          that();
>     }
>      else
>     {
>          this2();
>         that2();
>      }
> 
> _logically_ more readible than
> 
>     if (cond)  {
>         this();
>          that();
>     } else {
>          this2();
>          that2();
>     }
> 
> ?

Yes.  The inline braces are more difficult to see, they blend in with the if 
statement.  Plus, it's much easier to match a brace visually with another brace 
in the same column, instead of matching it with an 'if' or 'while' or whatever 
statement.

For instance, it's harder to spot a problem in this code:

if(cond1 || cond2)
   blah();
   if(cond3 || cond4) {
      this();
      that();
}

than in this code:

if(cond1 || cond2)
   blah();
   if(cond3 || cond4)
   {
      this();
      that();
}

because the braces obviously don't line up, but in the first, the braces don't 
line up anyways, you might miss that there is an if statement in the middle and 
think it's properly braced.

Anyways, this preference is extremely subjective, both ways enjoy huge support 
in different languages.  There is no "right" answer, but clearly there are 
functional benefits and drawbacks to both (not just completely one sided as you 
say).

-Steve



      


More information about the phobos mailing list