There was so much great software engineering cleanup in Qt 6 and 6.1. Really quite excellent.
But one thing I was sorry to see was the move to unsigned integers (size_t) for size and index values, for example in these analogous methods:
- Qwt5: int QwtPlotCurve::dataSize() const;
- Qwt6: size_t QwtSeriesStore<T>::dataSize() const;
I regard size_t as an historical mistake. Any value to which subtraction would be applied really should be signed. Note that making an integer unsigned of course doesn't protect against it being assigned what is (or should be) a negative value -- it only guarantees that if that happens, the result is a sometimes difficult-to-detect disaster.
It's not uncommon to assign (-1) to an undefined index variable. That can be recognized regardless of the size of the array to which it would be applied -- BUT ONLY if we sacrifice one little single bit to allow the representation of negative numbers. Note that a <size_t> value is NEVER < 0 (even if it is) -- a very likely coding mistake, resulting in invalid memory references -- or an infinite loop -- i.e. disaster.
And when applying dynamic offsets to an index, the result could certainly be negative, and the only way to detect that is to get your hands on the size of the array to which it would be applied, and using a non-intuitive expression, (>= size), for this condition.
Qwt5's choice of a (signed) int, as is used in Qt proper, for these values was better. $0.02 (and then some).
Bookmarks