Partially-Formed @ Meeting C++ 2021 talk is now online

My talk “Partially-Formed Objects For Fun And Profit” from Meeting C++ 2020 is now online here: https://www.youtube.com/watch?v=9OQKZl7ha7g

From the abstract:

Lately, partially-formed states have gained some traction as the natural state of moved-from objects. Alexander Stepanov, in his landmark book Elements of Programming (EoP), defines them as a state in which the only valid operations are assignment and destruction. This state was, and continues to be, essential to high-performance code, and to the C++ guarantee of “don’t pay for what you don’t use”.

We will also show how developers that feel uneasy about the partially-formed state can avoid them at little to no cost, neither in code readability, nor performance, and use these examples to propose a new (or old) paradigm for API design: safe and unsafe functions (in the Sean Parent sense).

A longer version of the talk, in which I also cover the Bonus Slides, for which I didn’t have time in the Meeting C++ version, is available from the MUC++ YouTube channel: https://www.youtube.com/watch?v=HcSAIZafNZU

RFC: How to fix a tricky leak in QFormLayout?

We have a nasty leak in QFormLayout::setWidget(). In setWidget(), we create the QWidgetItemV2 corresponding to the passed QWidget, and pass that on to Private::setItem, which has a bunch of error returns (guard clauses) that do not delete the item, among them negative row index and cell already occupied.

We could easily fix that missing delete, but this function is also used by setLayout(), say, where the item is the layout.

Conceptually deleting that item (= the nested layout) is completely OK, because the user should be able to rely on the form layout to take ownership of the nested layout, without ifs and buts.

But then we have code in tst_qformlayout that breaks. Simplified, it reads:

   QFormLayout layout;
   QHBoxLayout l4;
   layout.addLayout(-1, QFormLayout::FieldRole, &l4);

I guess you spot the problem? If l4 had been added, everything would’ve been peachy: The QHBoxLayout destructor unregistered itself from layout, which does not attempt to delete l4 when it itself is deleted.

But if l4 is not added for some reason, like in the test code above, the fixed code will attempt to delete l4, which is undefined behaviour, of course (double-delete).

I think such broken code deserves to be broken, for the greater good of fixing a resource leak. Esp. since a double-delete should complain much louder than a leak, and the API user can do something about the double-delete while she can’t do anything about the leak (the pointer is not reachable from outside QFormLayout).

I feel uneasy about adding this to 5.6 LTS, though, so I’ll make a minimal fix there, just for setWidget().

What do you think about the larger fix?

Effective Qt @ Meeting C++ 2015: talk is now online

Effective Qt continues as a conference-driven series!

After the guys at Qt World Summit last year managed to mess up the recording of exactly one of the many, many talks there (my Effective Qt one, of course), this is to let you know that Jens Weller of Meeting C++ has uploaded the recording of my Effective Qt talk to his conference channel on YouTube.

I talk about Q_FOREACH vs. C++11 range-for, QLatin1String vs. QStringLiteral, as well as, of course, how bad QList is.

Enjoy!

Heise Developer: GoingNative 2012 — Gegenwart und Zukunft von C++

For you German speakers out there, my sixth Heise Developer article, “GoingNative 2012 — Gegenwart und Zukunft von C++” just went live on Heise’s site.

It’s a sum-up of the GoingNative 2012 conference that happened on Feb 2nd-3rd. There won’t be an English translation later, since it’d be outdated by the time it appeared. The talks are in English, and you can download them all from Microsoft’s Channel9 page, though.

From the article:

Die Qualität der Vorträge war durchweg hoch, wenn auch Nichtmuttersprachler einigen Vortragenden nur schwer folgen konnten. Die Konferenz macht Lust auf ein Jahr mit mehr C++-Konferenzen als seit 1999 üblich. Besonders hängen blieben das Versprechen auf schnelle Adoption des neuen Standards, auch von Clang und Microsoft, und der Versuch, die C++-Standardbibliothek in den nächsten Jahren massiv zu erweitern.

GoingNative12 @ KDAB, Berlin

For everyone interested in C++11, and as suggested by Herb Sutter, KDAB will show the live stream of the GoingNative12 C++ conference in it’s training facilities at Tempelhofer Ufer 11 in Berlin this Thursday and Friday (Feb 2nd and 3rd). The show is scheduled to run from 18:30 to 02:15 (CET) each day. We invite everyone to join us, but please drop us a note at berlin(at)kdab.com so we can plan ahead.

Wild Beasts

In “Private Practice: Taming Templates”, I had (deliberately, of course :)) hidden a bug in the implementation of KDGenericFactory. I’ve now added a discussion about the bug and its fix.

Private Practice: What’s in a Proxy-Style?

A new session in the private practice, “What’s in a Proxy Style?”, examines QProxyStyle and derives some important caveat when applying a classical Design Pattern.

This is the original-language version of my recent Mythos Proxy-Style article.

Private Practice: Taming Templates

I’ve started a new column, Private Practice, that looks at existing implementations and examines them.

The first Private Practice article, Taming Templates, examines techniques to control template code bloat. There’s nothing particularly earth-shattering in there, but I noticed that a lot of people don’t seem to be aware of the fact that templates can cause a lot of duplicated code, so I thought I’d write about it.

Even if they haven’t been released under the Private Practice banner, the following articles also fit that category well:

Heise Developer: Mythos Proxy-Style

For you German speakers out there, my fifth Heise Developer article, “Mythos Proxy-Style: Wie eine verspätete Klasse neues Licht auf ein bekanntes Entwurfsmuster wirft” just went live on Heise’s site.

It examines the implementation of QProxyStyle in Qt 4.6 and, from that analysis, derives an important caveat regarding the applicability of a certain well-known design pattern.

This is the German translation of an unpublished English-language original, which I will publish here after a grace period.

From the article:

In der Qt-Gemeinde existiert ein Mythos: “QProxyStyle”. Auf der einen Seite stehen Entwickler wie David Faure, seines Zeichens KDE-Urgestein und geschätzter Kollege des Autors, die behaupten, ein QProxyStyle sei unmöglich. Auf der anderen Seite stehen Entwickler von Qt-Erweiterungen, die einen QProxyStyle entwickelt haben wollen. Eine Spurensuche im Märchenwald deckt interessante Komplikationen bei der Anwendung eines bekannten Entwurfsmusters auf.

Heise iX: QtQuick article, KDAB whitepaper; Qt Containers update

Together with my fellow KDABians Stephen Kelly and Volker Krause, I wrote a whitepaper on QtQuick usage in the KOMO project. From the whitepaper:

Developing a serious and large application from scratch, or from an existing desktop application, presents a different set of challenges compared to your normal smart-phone ‘app’. Portability to different platforms, and long-term maintainability in the face of ever-changing mobile target platforms suddenly come into play. This paper attempts to summarize the experience we gathered using the new declarative GUI framework, QtQuick, in this project.

Unfortunately, recent events (read: Tizen) have already invalidated much of the content in the supplemental box on the future of Qt, but that’s the bane of everyone writing about Qt’s future these days…

Get the English version (with slightly more details) at http://www.kdab.com/whitepapers, or read the German version (with better editing) in the current print issue of German computer magazine iX: http://www.heise.de/ix/inhalt/2011/11/114/.

In other news: I’ve updated “Understand the Qt Containers” with a discussion of the differences between STL and Qt containers regarding size types, associative container insertions, and error handling. I also mention QT_STRICT_ITERATORS now.