D style guide
    Ali Çehreli 
    acehreli at yahoo.com
       
    Mon Jun 17 09:36:49 PDT 2013
    
    
  
Please ignore my comments because they are bike-shedding. I am not sure 
about Phobos coding guidelines.
On 06/17/2013 09:13 AM, Joseph Rushton Wakeling wrote:
 >     * Space after if -- e.g. if (x < 0) not if(x < 0).  This isn't 
cited, and in
 >       fact the example given (at the end of the page) has no space 
after if.
 >       Also, what about other statements such as while, for, foreach, 
etc.?
I want that space. It is very common in most C++ guidelines as well.
 >     * Full bracing.  It's mentioned that opening braces should be on 
their own
 >       line, but not that braces should be used even in the case of 
single-line
 >       statements, i.e. that one should do,
 >
 >           if (x < 0)
 >           {
 >               negative = true;
 >           }
 >           else
 >           {
 >               negative = false;
 >           }
 >
 >       and not
 >
 >           if (x < 0)
 >               negative = true;
 >           else
 >               negative = false;
Yes, curly brackets are very helpful in readability even when there is 
no reason.
 >     * Use of brackets around sides of a conditional, e.g. to write
 >
 >           if (x + y < w * z)
 >
 >       and not
 >
 >           if ((x + y) < (w * z))
I am on the other side on that one: Use parentheses to show intent even 
when unnecessary.
 > I'd also appreciate guidelines about template if statements and 
indentation: is
 > it preferred to write e.g.
 >
 >      auto func(R)(R input)
 >          if(isInputRange!R)
 >      {
 >          ...
 >      }
 >
 > or,
 >
 >      auto func(R)(R input)
 >      if(isInputRange!R)
 >      {
 >          ...
 >      }
 >
 > I see both in Phobos.  I must say I prefer the former, as it somehow 
highlights
 > the presence of the 'if' statement
Me too: Indentation helps with readability.
 > Same for in/out contracts: is it preferred to have,
 >
 >      auto func(...)
 >          in
 >          {
 >              ...
 >          }
 >          out
 >          {
 >              ...
 >          }
 >      body
 >      {
 >          ...
 >      }
 >
 > ... or all on the same indentation level?  (Again, I personally 
prefer the
 > indentation of the in/out blocks.)
I don't like that indentation.
I know that Phobos wants the opening curly bracket on its own and that's 
what I am used to elsewhere, but I have gotten used to seeing it at the 
end of the previous line. Except, I still don't like it for functions 
(member or regular), structs, classes, version, etc. I think I like it 
only after control-flow keywords like if, foreach, while, etc.
But if we go with others' preference, then I have seen code like this:
auto func(...)
in {
     ...
} out {
     ...
} body {
     ...
}
Getting back to your question: I don't know. :p
Ali
    
    
More information about the Digitalmars-d-learn
mailing list