[Interest] The willy-nilly deletion of convenience methods (was: Mixing Commercial and Open...)

Jason H jhihn at gmx.com
Wed Mar 24 15:33:35 CET 2021


>
> Probably. There's only so much space for the message in them. I'm trying
> to point out that the specific motivation here isn't even remotely
> _technical_ (e.g. is this hard to implement correctly; as you've shown,
> it's super easy), but a _design_ one (is this API *good*?).
>
> And anyways these methods are still fully supported within Qt 5.

I want to "code less, create more". And manually writing these over and over
for every project I use Qt in is not coding less. They should be part of
the library.

> This is calling for a more generic toX() API. Which isn't easy to
> provide within the quality constraints of QtCore. If it were, don't you
> think Yours Truly would already have provided it? Do I sound *that* evil
> that I enjoy crippling for the sake of it? :-(

I'd rather an ANPI where you have to call toX() a minimal number of times.
See below.

> Miscellanea examples from Qt itself,
>
> * I need to remove duplicates from my list, let me do:
>
> > list = list.toSet().toList();

This should just be toSet() and generic iteration after that. No need
to convert it to a list if you can iterate over QSets the same as QLists.

> * I need to keep the list, process it in order, but avoid processing
> duplicate elements; 99% of the time the list is a handful of elements;
> let me do
>
> > QSet s; for (elem : list) { if (!s.contains(elem)) { s.insert(elem); process(elem); } }
> * I've got a square peg (a QList) and a round hole (an function I made
> that takes a QSet), so I need conversions to call it.

The elephant in the room is that Qt5 QList an QVector can have majorly different
impacts on memory. A QList<LargeClass> is more tolerant of memory fragmentation
than QVector<LargeClass> as you need o reallocate a contiguous chunk of
memory successfully. Where as Qt6 QList would allow LargeClass objects to be scattered.
This is no longer the case in Qt6. You'll be forcing everything into contiguous memory.
Which also has impacts on performance for systems with virtual memory.
Please tell me I'm wrong about this?

I wanted a generic iterator.  Typdefing QList to QVector does not solve that.
But even so, how do I generically iterate over QVector/QSet?



More information about the Interest mailing list