[Development] commas in ctor-init-lists

Alberto Mardegan mardy at users.sourceforge.net
Wed Jun 1 20:57:12 CEST 2016


On 01/06/2016 18:12, Mathias Hasselmann wrote:
> Yes, when it comes to initializer lists the trailing comma looks ugly to
> me. Because of the inconsistent two-space indent for the first
> initializer. Because line starts of are not aligned.

In my projects I use this style:

MyObject::MyObject():
    SuperClass(),
    m_var1(),
    m_var2()
{
}

Having a diff taking two lines never annoyed me, especially given that
often the last member is either d_ptr() or q_ptr(), so I usually add
members in the middle.

> Not mentioned yet: Conditional compilation vs. stable ABI:
> 
>     MamanBar::MamanBar(...)
>         : m_field1(...),
>           m_field2(...),    // oh...
> #ifdef FEATURE1_ENABLED
>           m_field3(...),     // ...ah
> #endif
> #ifdef FEATURE2_ENABLED
>           m_field4(...)
> #endif
>     {
>     } 

You can always find cases which break with either style.

    MamanBar::MamanBar(...)
#ifdef FEATURE1_ENABLED
        : m_field1(...) // ...ah
#endif
        , m_field2(...)
        , m_field3(...)
    {
    }

Ultimately, it's just a matter of personal preferences; people like to
argue about diff size or better spotting of obvious mistakes (when
putting operators at the beginning of the line), while as a matter of
fact people can live perfectly well and be equally productive with
either style.

Ciao,
  Alberto



More information about the Development mailing list