[Development] Use of Standard Library containers in Qt source code

Marc Mutz marc.mutz at kdab.com
Wed Jul 6 11:08:22 CEST 2016


On Sunday 03 July 2016 12:04:14 Stephen Kelly wrote:
> It is not possible to reason about code like that. I have the feeling that 
> faced with code like that, people just don't attempt to reason about it 
> while at the same time trying to get on with what they are trying to do.

The underlying theme here, I think, is: idiomatic code. Qt has its set of 
idioms (like ending QObject subclass ctors in QObject *parent=nullptr), but it 
largely ignores C++ idioms. And that leads to complicated code and throws off 
contributors that are used to idiomatic C++.

Take this example:

https://codereview.qt-project.org/159693

The copy-swap idiom is two decades old (at least as old as Effective C++ 
ed. 1), but the only uses in Qt are those that I introduced myself. Following 
the idiom trivialises the implementation of both copy and move assignment 
operators. Not following it leads to bugs such as the one linked above.

Using algorithms is idiomatic. too: erase-remove is an idiom, also nearing two 
decades old. It reduces bugs, and helps grok the code for those that know the 
idioms, but, like in any other language, if you don't know the idioms, you 
don't really understand the language.

C++ is the language Qt is written in. You need to learn the language's idioms.

-- 
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



More information about the Development mailing list