[Development] commas in ctor-init-lists

Sergio Martins sergio.martins at kdab.com
Wed Jun 1 16:33:39 CEST 2016


On Wednesday, 1 June 2016 15:44:22 WEST Marc Mutz wrote:
> On Wednesday 01 June 2016 15:15:17 Sergio Martins wrote:
> > Subjective reasons against leading commas:
> > - It's ugly
> > 
> > Subjective reasons against trailling commas:
> > - It's ugly
> 
> I beg your pardon? Trailing commas are ugly? So where's the text editor that
> folds prose text to have commas on the next line?

What does prose text have to do with C++ ? When people say readable code 
resembles english it's not about punctuation. It just means you can understand 
the business logic by reading the variable and function names:

while (isSick) { eatApples(); }

You're pushing the analogy too far.

> 
> > - You can comment it out by commenting only 1 line
> > - Code generators / tooling only have to touch 1 line to add or remove
> 
> All these are also valid for enums and function argument lists, but I see
> no- one doing similar things for enums and functions.

What does function arguments have to do with ctor-init-lists ? The number of 
member variables to initialize scales linearly with the number of features, 
can you say the same about functions ? Do you keep growing your function until 
you have 10 or 20 arguments ? I don't care about commas in functions, I 
refactor the function instead.

Agreed about enums, but I write a order of magnitude more ctors than enums, so 
never felt motivated to use C++11 trailling enum feature.


Regards,
-- 
SĂ©rgio Martins | sergio.martins at kdab.com | Senior Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - The Qt Experts



More information about the Development mailing list