[Qt-creator] Using C++11 in Creator's source

André Pönitz apoenitz at t-online.de
Wed Mar 5 21:03:43 CET 2014


On Wed, Mar 05, 2014 at 12:20:45PM +0100, Bojan Petrović wrote:
> I've been using auto for quite some time now.
> 
> My "rules" are to use it to avoid repeating a type in one line and to avoid
> writing the types of very long iterator types.

"Use if it avoids repetition within a line" sounds like a pretty good base
rule as it has a tendency to remove actual noise without obvious drawbacks.

> So I wouldn't use auto in these two cases:
 
> > auto myAction = menu->addAction(…);
> > foreach (auto ….)

I think I agree. This obfuscates the code.

I _know_ what I can do with 'myAction' when defined as

    QAction *myAction = menu->addAction(…);

without looking any further.

I don't know at all, certainly not from a glance, what expect from

    auto myAction = menu->addAction(…);

and even trying to find out takes extra keystrokes for cursor positioning and
lookup (and require a properly working codemodel...)

Repeat a couple of times and any possible initial benefit from not having
to type "a lot more" is gone.

> I used it for some time in foreach, but after getting back to read my older the
> code that used auto there, I found that the code would be more readable if I
> had put the type there.

That would have been my gut feeling...

> Similar could be argued for iterator types, but they are usually so long that
> I'd rather jump to declaration of container than having the iterator type
> spelled out.

Same ;-)

Andre'



More information about the Qt-creator mailing list