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.m...@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts
From 62027ef0559c235adc0d49fb49a75c47a5cc8f92 Mon Sep 17 00:00:00 2001
From: Marc Mutz <marc.m...@kdab.com>
Date: Fri, 3 Jun 2016 14:46:07 +0200
Subject: [PATCH] QLabelPrivate: use nsdmi

Change-Id: Ib094a2c01bb4009c780423b810546681591c2a96
---
 src/widgets/widgets/qlabel.cpp |   26 --------------------------
 src/widgets/widgets/qlabel_p.h |   22 +++++++++++-----------
 2 files changed, 11 insertions(+), 37 deletions(-)

diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp
index 5db1013..c12710b 100644
--- a/src/widgets/widgets/qlabel.cpp
+++ b/src/widgets/widgets/qlabel.cpp
@@ -61,33 +61,7 @@ QT_BEGIN_NAMESPACE
 
 QLabelPrivate::QLabelPrivate()
     : QFramePrivate(),
-      sh(),
-      msh(),
-      text(),
-      pixmap(Q_NULLPTR),
-      scaledpixmap(Q_NULLPTR),
-      cachedimage(Q_NULLPTR),
-#ifndef QT_NO_PICTURE
-      picture(Q_NULLPTR),
-#endif
-#ifndef QT_NO_MOVIE
-      movie(),
-#endif
-      control(Q_NULLPTR),
-      shortcutCursor(),
-#ifndef QT_NO_CURSOR
-      cursor(),
-#endif
-#ifndef QT_NO_SHORTCUT
-      buddy(),
-      shortcutId(0),
-#endif
-      textformat(Qt::AutoText),
-      textInteractionFlags(Qt::LinksAccessibleByMouse),
       sizePolicy(),
-      margin(0),
-      align(Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs),
-      indent(-1),
       valid_hints(false),
       scaledcontents(false),
       textLayoutDirty(false),
diff --git a/src/widgets/widgets/qlabel_p.h b/src/widgets/widgets/qlabel_p.h
index dce9ba7..9c687e27 100644
--- a/src/widgets/widgets/qlabel_p.h
+++ b/src/widgets/widgets/qlabel_p.h
@@ -109,30 +109,30 @@ public:
     mutable QSize sh;
     mutable QSize msh;
     QString text;
-    QPixmap  *pixmap;
-    QPixmap *scaledpixmap;
-    QImage *cachedimage;
+    QPixmap *pixmap = nullptr;
+    QPixmap *scaledpixmap = nullptr;
+    QImage *cachedimage = nullptr;
 #ifndef QT_NO_PICTURE
-    QPicture *picture;
+    QPicture *picture = nullptr;
 #endif
 #ifndef QT_NO_MOVIE
     QPointer<QMovie> movie;
 #endif
-    mutable QWidgetTextControl *control;
+    mutable QWidgetTextControl *control = nullptr;
     mutable QTextCursor shortcutCursor;
 #ifndef QT_NO_CURSOR
     QCursor cursor;
 #endif
 #ifndef QT_NO_SHORTCUT
     QPointer<QWidget> buddy;
-    int shortcutId;
+    int shortcutId = 0;
 #endif
-    Qt::TextFormat textformat;
-    Qt::TextInteractionFlags textInteractionFlags;
+    Qt::TextFormat textformat = Qt::AutoText;
+    Qt::TextInteractionFlags textInteractionFlags = Qt::LinksAccessibleByMouse;
     mutable QSizePolicy sizePolicy;
-    int margin;
-    ushort align;
-    short indent;
+    int margin = 0;
+    ushort align = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs;
+    short indent = -1;
     mutable uint valid_hints : 1;
     uint scaledcontents : 1;
     mutable uint textLayoutDirty : 1;
-- 
1.7.10.4

_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to