[Development] commas in ctor-init-lists
Marc Mutz
marc.mutz at kdab.com
Fri Jun 3 14:52:07 CEST 2016
On Friday 03 June 2016 14:26:03 André Somers wrote:
> Op 03/06/2016 om 13:53 schreef Marc Mutz:
> > On Friday 03 June 2016 10:05:52 Edward Welbourne wrote:
> >> if (somee.really(long.and.complicated, expression) ||
> >> another.such(that,
> >>
> >> makes, the.line.too.long) || and.then.some.more())
> >
> > To be perfectly blunt: such expressions shouldn't be allowed. Period.
> > Neither with nor without line breaks. Such monsters should be subjected
> > to Extract Method with extreme prejudice.
> >
> > Thanks,
> > Marc
>
> Fine. Lets replace it with something like this then:
>
> if (theValue ==
> MyNameSpace::MyLongAndComplicatedClassName::MyClassEnum::TheValue1 ||
> theValue ==
> MyNameSpace::MyLongAndComplicatedClassName::MyClassEnum::TheValue2 ||
> theValue ==
> MyNameSpace::MyLongAndComplicatedClassName::MyClassEnum::TheValue3) {
>
> }
Umm... same thing?
What I'm saying is:
- Multi-line conditions in if statements should *always* be refactored to a
single function call.
Then we don't need to talk about how to format multi-line ifs at all, because
they do not exist anymore.
Same goes for other expressions, too, really, but a free statement is much
easier line-wrapped than an if, whose then-clause' opening brace is lost in
complete noise with a multi-line if statement.
I was also saying earlier, but it probably was overlooked:
- Conditional compilation members should be initied by nsdmi (or placed in a
struct with a default ctor that inits the values, so the member of struct
type can be omitted from the ctor-init-list).
And we can leave trailing comma ctor-init-lists in, because there will be no
more conditional compilation in ctor-init-lists. And with a minimum of
foresight, a class author will place a field last than can stay last, to
accomodate new fields. Even the subset of C++11 features that we can use will
make much of the argumentation for leading commas moot. Even more so if we
find (qcd.h doesn't track it) that we can also use trailing comma in enums.
We have the same problem in .pro files: QtC just appends new files, always
creating a patch the churns the old-last line in SOURCES. If it would sort
them in lexicographically, most additions would be one-liners.
Here's an example (QLabel) which was problematic in the past because of the
many preprocessor conditionals (attached). NSDMI doesn't work for bit-fields,
but if I were to finish that patch, the bit fields would probably be replaced
by a uint flags field.
Thanks,
Marc
--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-QLabelPrivate-use-nsdmi.patch
Type: text/x-patch
Size: 2855 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160603/12208dd0/attachment.bin>
More information about the Development
mailing list