[Interest] QVariant compare operator
Thiago Macieira
thiago.macieira at intel.com
Mon Apr 20 17:50:06 CEST 2020
On Monday, 20 April 2020 03:28:48 MDT Florian Bruhin wrote:
> FWIW that's the choice Python had taken with Python 2 (ordering different
> types by their type name). It was widely regarded as a bad decision and
> replaced by a TypeError exception in Python 3.
Interesting. Do you have more information on why it is regarded a bad
decision? A PEP, hopefully?
Either solution can be dealt with by the surrounding code. If one wants not to
sort across types and QVariant does, then all you need to do is to compare the
types before. If one want to sort by type and QVariant doesn't, then one needs
to convert to a specific common type before issuing the comparisons.
The pros of having that conversion inside QVariant is that it reduces the
chance of someone getting it wrong. This reduces code duplication in favour of
a well-tested implementation.
The drawback is that it might not be the order you want because the conversion
isnt the one you wanted. Some conversions are lossy and may result in spurious
or nonsensical comparisons. That means some applications may need to deploy
their own conversion code regardless of what QVariant does. For those and the
others that don't need comparisons across types, QVariant has unnecessary
complexity.
So, again, it boils down to choice. I'm really interested in Python's
rationale to see if it applies to us too.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel System Software Products
More information about the Interest
mailing list