Coding Style - C++ constructor initialization list
Dirk Hohndel
dirk at hohndel.org
Mon Mar 23 05:51:26 PDT 2015
On Mon, Mar 23, 2015 at 12:59:39AM -0300, Marcos Cardinot wrote:
> Hello folks,
>
> It is just a naive discussion about coding style... =D
Our favorite topic :-)
> According to the CodingStyle.txt:
>
> *"- in a C++ constructor initialization list, the colon is on the same line
> and*
> * continuation lines are aligned as the rule above:*
>
> * ClassName::ClassName() : x(1), y(2),*
> * z(3)*
> * {*
> * }"*
Whitespace did you in here.
Yes, it turns out that this is not quite what the we ended up with.
> As you know, most of the classes does not follow this rule yet, but it's
> fine, since it looks like a new rule =D
>
> However, in this format, the next lines would usually require some white
> spaces (in order to do a correct alignment), but it might not be a good
> idea, because the alignment would depends on the editor...
Well, no. Tab is 8 spaces so this is not editor specific
> In addition, writing many (more than one) members at the same line is less
> readable than writing only one...
>
> My suggestion is that for this case, we should have a style in which we
> would never need to use white spaces...
> for example:
> *ClassName::ClassName() :*
> *x(1),*
> *y(2),*
> *z(3)*
> *{*
> *}*
This isn't readable for me. Possibly a mail formating issue.
What we really have and should have is
ClassName::memberFunction() : x(1),
y(2),
z(3)
{
}
So y and z are indented by exactly one tab.
> *ClassName::ClassName()*
> * : **x(1),*
NO. I absolutely hate having the "connecting" character at the start of
the next line.
/D
More information about the subsurface
mailing list