What is the correct use of auto?

Georg Wrede georg at nospam.org
Sun Apr 13 13:58:54 PDT 2008


Robert Fraser wrote:
> Georg Wrede wrote:
>> Robert Fraser wrote:
>>> Hans W. Uhlig wrote:
>>>
>>>> I have been reading through the specification and playing with D 
>>>> more and more, what is the purpose of auto. I can understand in 
>>>> languages with scalar types handling datatypes on assignment but on 
>>>> a strictly typed language like C or D when would auto(as a variable 
>>>> declaration) provide more useful functionality then it removes from 
>>>> readability.
>>>>
>>>> When would this be useful rather then simply specifying the type?
>>>
>>> I want to (someday, not any time soon) add a feature to Descent 
>>> whereby "auto" can be converted to the actual type automatically 
>>> throughout a source file. That way, you can get the advantages of 
>>> less typing (as in "Punch the keys for God's sake", not "int vs. 
>>> long") while still getting the readability after the refactoring.
>>
>> I wouldn't use that feature.
>>
>> I admit, in the beginning, I was against auto, but today, I think it's 
>> an excellent thing. And not because it could (in some situations) save 
>> typing.
> 
> FWIW, neither would I (since it kills the portability/maintainability 
> aspect of auto). But it would be nice to have for people who do want it.
> 
> Actually, I would run it on all the Tango examples, since "auto" has no 
> place in examples -- If I'm learning how to use an API, I want to know 
> the actual types of the stuff I'm getting without looking up every 
> function.

THIS is something I've posted reams about, ever since auto became part of D!

While auto might (and probably is) an everyday part of Good D Code, it 
STILL has no place in examples.

(( An example: My 8 and 10 years old sons walked with me today. Neither 
looked left nor right when we crossed the street. I told them (for the 
200th time) that, "hey, Daddy gets distracted with you guys fooling 
around, and if Daddy misses a coming car, then we all die". Next 
crossing, and I was the only one who even tried to look around.

OK, safety (like in buckling up (non-US: wearing safety belts in a 
car)), has nothing to do with this comment. The only point here is, that 
for people who don't *personally* "see" the point, no amount of nagging 
seems to drive the issue through. And "auto" with D examples, seems to 
be the same. Unfortunately. ))

So, please, never again a D code example with auto. Thank you all!!!



More information about the Digitalmars-d mailing list