New D coding convention style guide (brace formatting)
Kristian
kjkilpi at gmail.com
Wed Aug 23 00:35:17 PDT 2006
On Wed, 23 Aug 2006 04:41:01 +0300, Charles D Hixson
<charleshixsn at earthlink.net> wrote:
> Bruno Medeiros wrote:
>> Walter Bright wrote:
>>>
>>> http://thc.segfault.net/root/phun/unmaintain.html
>>> From - Mon
>> Speaking of which (but seriously), we may not get a consensus on tabs,
>> and maybe justifiedly so, but one other thing with DMD's coding
>> convention that troubles me is the braces formatting:
>> if (b)
>> { dg();
>> return true;
>> }
>> ...
>> ?
>
> My personal preference is:
> if (b)
> { dg();
> return true;
> }
> with all the indentations managed by tabs, so you can decide how much
> indenting you find useful. (I normally choose 3 spaces...but there are
> times when I compress it down to two, and I used to usually use 4
> spaces.)
>
> I'd be surprised if this was the most common choice, however.
That one I haven't seen yet. :)
Well, if you like to see an uncommon case (I think), here's a one, heheh.
It's the one I prefer:
if(b) {
dg();
return true;
}
Before you feel sorry for me, there is a point for using it, and it is
cases where you don't use brackets.
For example, compare the following cases:
//case 1
if(b) {
doX();
doY();
}
else {
doY();
doZ();
}
//case 2
if(b)
doX();
else
doY();
//case 1 + 2
if(b) {
doX();
doY();
}
else
doY();
See how similar the cases are, and how they fit together. Indention tells
where a block or single line statement starts. And where it ends, you may
ask? Well, of course, it ends before the next one starts. (Code will look
like there were a caption and paragraph(s), a caption and paragraph(s),
etc.)
I know any syntax can look weird, until you get accustomed to it. And you
can get accustomed to a lot of things.
More information about the Digitalmars-d-announce
mailing list