[Development] Use of Standard Library containers in Qt source code
Stephen Kelly
steveire at gmail.com
Sat Jul 2 16:30:18 CEST 2016
Benjamin TERRIER wrote:
>> However, everyone else is excluded by it. When my colleagues find long
>> functions, lots of nested if()s and for()s, ++foo somewhere in while
> loops,
>> they find it much harder to reason about the code. Now I do too.
>>
>> So, by sticking to lots of raw loops, you're actually actively excluding
>> other parts of the C++ community from participating. I don't have numbers
> to
>> qualify it, but there seems to me to be a much larger community following
>> modern C++ practices than following Qt practices on questions like this.
>
> You can't say that using raw loops (vs stl algorithms) is "actively
> excluding" any C++ developer.
Yes, maybe 'actively' was not correct.
> But how come a raw loop can be excluding? It should be understandable by
> any C++ developer and, I would dare to say, by any C-style programming
> language developer.
I don't think anyone can understand or reason about raw-loop-heavy code (see
PS below). I use 'excluded' to refer to people who are not willing to do so.
They exclude themselves from working on Qt code because they can not reason
about it.
In the same sense, Thiago is 'excluded' from reading and understanding code
which uses 'container.empty()' or which doesn't use raw-loops, because he
would choose to not work on such code.
There is a divide. The 'exclusion' is self-decided.
Does that make sense? If you have a better phrase than 'self-exclusion' for
that then it could be useful to share it.
Thanks,
Steve.
PS: Take QQuickListViewPrivate::applyInsertionChange as it is currently
written as an example:
http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quick/items/qquicklistview.cpp?id=5d23470b#n3068
There's a `++index` somewhere in the middle 3 scopes deep. Further up in the
function `index` is assigned, but then assigned again (conditionally) from
the `count` of a container. Then `index` is used later in the function, but
I can't reason about what it is when it is used.
There are many other problems with that function, which are caused by many
'raw' loops nested up to four levels, affecting variables assigned outside
top-level if() conditions half a page up. Extracting such code into named
functions would indicate the intent of the function.
Someone unwilling to attempt to reason about the code in that function is
'excluded' from fixing something in it or extending whatever features it
has.
More information about the Development
mailing list