[Development] Use of Standard Library containers in Qt source code
julien.blanc at nmc-company.com
Mon Jul 4 08:14:21 CEST 2016
Le samedi 02 juillet 2016 à 10:10 -0700, Thiago Macieira a écrit :
> On sábado, 2 de julho de 2016 15:44:50 PDT Mark Gaiser wrote:
> > I don't get why you would be confused by - for instance - the empty
> > method.
> > STL has that method, but so does Qt  apparently in an attempt to be
> > compatible with the STL API.
> That doesn't mean we will allow the use of those methods in our own libraries.
> I *will* reject any code that uses empty() to mean isEmpty() on a Qt
> The whole point of this thread is that using certain methods is misleading or,
> at best, confusing.
While I agree with you that isEmpty is a far better name than empty, I
don’t think renaming is the best idea.
As for the argument of using size() == 0 (which I prefer over renaming),
note that :
- std::forward_list does not have a size() member
- std::list size() may have linear complexity before C++11
About the example you gave, I see two things that could be improved,
with a much broader scope than just empty -> isEmpty (which is a
particular case) :
- the use of side-effects functions (aka : non const) in conditionals :
IMHO they’re bad for readability, especially if the condition is a bit
complex. If it is banned (or, banned unless commented), then there is no
- visual distinction between const / non-const functions / variables
usages in QtCreator/whatever ide you’re using. This one would be a
must : the fact that empty is const makes it really clear what it does,
but you currently have to either know it or read the doc.
Following Stephen Kelly’s mails, I’m convinced that instead of wrapping
stl containers, implementing a free function qIsEmpty is less work and
addresses all your readability concerns.
More information about the Development