[squid-dev] Fwd: [PATCH] for loops modernization

Amos Jeffries squid3 at treenet.co.nz
Thu Mar 16 05:10:19 UTC 2017


On 16/03/2017 5:03 a.m., Adam Majer wrote:
> On 03/15/2017 04:38 PM, Alex Rousskov wrote:
>> On 03/15/2017 06:57 AM, Adam Majer wrote:
>>> If you really want to fix this, avoid `auto` in code people actually
>>> want to maintain. The only place it is actually useful is in heavily
>>> templated code and that is the main reason it was introduced. It was not
>>> introduced so you can avoid typing the name of POS (plain old
>>> structures) or types or classes.
>>

IMO, and since I'm mostly the one doing these changes will probably be
the usual way going forward - is that if the type being used is complex
enough to actually have/need a typedef to make the type name simpler,
then auto is appropriate.

Specifically the way we historically have acronyms as typedef labels
means one often has to lookup or pay specific attention to what the
definition was anyway. So looking up an auto is no worse and at least
auto does not pretend to be a class name somewhere.

I also find (so far, and specifically with Squid code) that with
range-for loops the name of the variable/getter function/method on the
RHS of the range-for first line is usually more important to know how
its best used than exact iterator type. If that name is not
self-documenting what the object being handled is we have a larger
problem to fix first which may change whether range-for is appropriate
at all.

Other uses of auto are context-specific, but yes it can be less useful
than one would extect from the hype.

Amos



More information about the squid-dev mailing list