[Qt5-feedback] Lambdas

BRM bm_witness at yahoo.com
Thu Jun 30 11:53:29 CEST 2011


----- Original Message ----

> From: Thiago Macieira <thiago at kde.org>
> Em Thursday, 30 de June de 2011, às 08:19:09, Konrad Rosenbaum escreveu:
> >  It feels much more natural to write something like mylsist.contains(...) 
> > than qContains(mylist,...) - Qt is supposed to be object oriented after  
all.
> 
> It would be 
> 
>     if (qFind(mylist, [](Type t)  { return t.isFoo(); }) != mylist.end())
> 
> But anyway, that's a question to  OO developers: where do you draw the line? 
> The purpose of a class is to  protect and mutate the invariant, the internals 
> that the class is holding.  It's not supposed to do everything under the sun. 
> For example, QDate will  not have a method QDate QDate::firstFridayThisMonth() 

> const.
> 
> I  personally think that the kind of container operations you're asking for are 
>
> just too specific to be part of the class. I'd prefer to have them outside. 
> 
> Yesterday, Konstantin was asking me for a 
> 
>      qFiltered(InputIterator, InputIterator, const T &value)
> 
> that would  return a list containing just the values that matched. So are we 
> going to  add all of the QtConcurrent operations too? filtered, filterReduced, 

> mapped,  mapReduced?
> 

While I quite agree that a line has to be drawn somewhere, I also find it a 
little annoying that for some containers there is a built-in find(), while for 
others there are not.
So from that perspective, I would argue that there should be some consistency 
between find()/contains()/etc that use default quick-methods - even if they just 
default to using the qFind()/etc functions and make a nice wrapper around them.

So, from my perspective - the containers _should_ have a basic functionality as 
being requested. It need not meet every circumstance - let the other qFind*/etc 
functions take care of that.
For instance, if I want to ensure that I search mylist using a binary search, 
then qBinaryFind() is what I want. If I could care less, then I should be able 
to just do mylist.find().
Having a contains() function is also very useful for QVector, QList, etc as it 
makes for a very quick way to determine if something is there using syntax that 
is natural and straight forward.
Lambdas may enable one do so - but then the syntax is not nearly as reader 
friendly - even without the lambdas it's not reader friendly.

Just $0.02 on the topic.

HTH,

Ben



More information about the Qt5-feedback mailing list