[Development] QtCS 2017 QtCore sessions

André Somers andre at familiesomers.nl
Thu Nov 2 05:55:18 CET 2017



Op 01/11/2017 om 22:27 schreef Thiago Macieira:
> On quarta-feira, 1 de novembro de 2017 13:15:11 PDT André Somers wrote:
>> That doesn't make sense. Of course it allows for that.
>>
>> You'd give indexOf a flag like Qt::searchTowardsBeginning (default being
>> Qt::searchTowardsEnd) to determine the direction to search in. Or do you
>> mean that you want the result also to be counted from the end? 
> You're confusing lastIndexOf() which searchs backwards from the end with 
> indexOf() searching forwards from a position near the end.
Yes, those two are orthogonal. Fine. That doesn't disqualify the
solution IMO. In fact, I already separated the two in the suggested
mock-API.
>
>> If all
>> API's take the index counted from the begining there would not be much
>> use for that. You either calculate it yourself by substracting the
>> result from length(), or you add another flag and do something like
>> std::optional<qsize> indexOf(needle, startIndex,
>> Qt::searchTowardsBeginning | Qt::asCountedFromEnd) .
> Yeah, we won't do that. The QString, QByteArray and QVector can't be bigger 
> than the maximum size representable in qssize_t anyway. So we don't *need* the 
> extra bit.
Fine, but the argument was not about that. The comment I made was on if
using negative indexes is good API to begin with. I think it is not.

>
> Since we don't need the extra bit, we will stick to signed because of its 
> benefits:
>  1) overflow can be caught with sanitisers
>  2) doesn't cause sign conversion warnings when converted to other signed 
>    values
>  3) the instruction from the committee is to use signed unless you explicitly 
>    need modulo-2 overflow
>  4) the standard library, if ever rewritten, will use signed counters
>
All that is really orthogonal to if you use negative indices as part of
your API, which was what I was responding to in the first place. You
used _that_ as an argument before, and I suggested that that is not such
great API IMHO and nowadays I'd do that differently. However, the world
we live in is one where Qt has had the current API for ages and changing
that would break too much.

André





More information about the Development mailing list