What is the correct use of auto?
Ary Borenszweig
ary at esperanto.org.ar
Fri Apr 11 16:32:59 PDT 2008
Ary Borenszweig escribió:
> Robert Fraser escribió:
>> 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 thought that too. :-)
>
> It can be done very easily, since bindings already have this
> information, but AST rewriting must be finished (but for this, only the
> code that rewrites a variable declaration).
In fact, if you hover over an auto variable, Descent will tell you it's
type. And, of course, autocompletion works as expected. (yes, with all
the bugs, but I'm hoping to release soon something that works flawlessly).
This answers the question "When would this be useful rather then simply
specifying the type?": when you are lazy to type the type, or you just
don't care.
More information about the Digitalmars-d
mailing list