[Interest] Why does QML prefer 'count' over '.length'?

J-P Nurmi jpnurmi at qt.io
Thu Jul 28 17:05:59 CEST 2016


On Thursday, July 28, 2016 15:46, Jason H <jhihn at gmx.com> wrote:
> Look, I know JS was invented in 10 days back in 1995. There's no shortage of things to complain about. But
> 'length' was chosen, and it is the number of items. I would agree with you that length is not as good as 'count', but
> the language is the language. Qt should move to be in compliance wit the language because JS was using it first,
> then Qt moved into JS. Unless you want to convince JS they should add count to everything as well. And I assure
> you there is more lines of JS using length than all lines of QML put together.
> 
> Consider the absurdity of the reverse:
> Why don't we ditch .length in QML and just make everything count?

Nobody is saying that 'length' wouldn't make sense for JS arrays or the generic Qt containers. 'Length' does make perfect sense in that context.

What I've been trying to say that comparing JS array to QML ListModel is like comparing QList or QVector to QAbstractItemModel. That does not make sense. They have different APIs and different needs. They are not interchangeable components even if your code snippet attempts to make it look like that. While primitive containers can be used in any context, item models are deliberately designed to feed data to item views. That is the context where 'count' wins 'length' hands down.

--
J-P Nurmi


More information about the Interest mailing list