[Development] RFC: more liberal 'auto' rules?

Marc Mutz marc.mutz at kdab.com
Fri Dec 4 14:07:10 CET 2015

On Friday 04 December 2015 09:13:33 Thiago Macieira wrote:
> You're calling for "opt-in by default" approach, while I am calling for an 
> "opt-out by default" approach. Since we need to decide which C++ features
> to  use in the first place due to old compilers we need to support, I
> think we're effectively "opt-out by default".

Opt-in for _which_ C++ features to use, sure.

But opt-out of _how_ to use them, vis a vis the greater C++ community.

The guidelines on lambdas in the coding standard are pretty good in that 
regard. They point out specific compiler bugs (some of which may no longer play 
a role in 5.7, e.g. MSVC 2010), and mandate certain workarounds, but do not 
further restrict the use of lambdas.

The guideline for auto is not at all like that, though.

Given a (beautiful) auto variable and an (ugly) lambda, I'd say that it's 
lambdas which make the code less readable, not auto. But if readability is 
only defined as "I can see all types", then the reverse it true, yes.

On Friday 04 December 2015 10:45:06 Blasche Alexander wrote:
>  For me the point is that if I have to look up a function signature to
>  figure out what type is behind the return values auto type then that's
>  bad.

Playing the devil's advocate here, I wonder how we could have accepted code 
like this before:


after all, you have to "look up the description() signature to figure out which 
type" is being passed to setText(), as defined above. We all write code like 
the above. And not only if the involved functions scream "it's QString, 

But now people (not saying 'you') will be vehemently -1'ing the completely 
equivalent code

   const auto desc = foo.description();

on grounds of reduced readbility compared to

   const QString desc = foo.description();

That makes no sense.

And as an aside, since it has been mentioned in this thread: in Python _all_ 
variables are 'auto'. All. Without exception. Are Python programmers more 
intelligent? Or do they just tolerate more pain? :)


Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts

More information about the Development mailing list