auto
Ary Manzana
ary at esperanto.org.ar
Fri Jun 22 04:24:19 PDT 2007
Bill Baxter escribió:
> Derek Parnell wrote:
>> On Wed, 20 Jun 2007 21:37:44 -0200, Ary Manzana wrote:
>>
>>> Derek Parnell escribió:
>>>> On Wed, 20 Jun 2007 14:20:43 +0200, Hoenir wrote:
>>>>
>>>>> I still can't get the purpose of "auto".
>>>>> I know it makes it possible to e.g. write "auto y = 4u;" but why
>>>>> not just "uint y = 4;"?
>>>> auto y = someFunc(); // What type is it now?
>>>>
>>> // What can you do with y now, if you don't know the type?
>>
>> Pass it to a function that does know its type.
>>
>
> I *think* the point was just that the code becomes less readable without
> any obvious indication of what type you've got. Sure you can do all the
> same things you could do it the type were explicit, but someone else
> asked to fix this code is going to have to track down "someFunc()" to
> see what it returns.
Thanks for this! This is exacly my thought, although I couldn't have
expressed myself that well.
I also agree with the situations you describe below, and also with
number 6 of Frits. I'll not use it anywhere else, since having the type
is more self documenting in a function.
>
> Lacking any particular extenuating circumstances, I agree that that
> making types explicit is better than using auto. But auto makes sense when
> 1) the actual type is a built-in (auto x = foo.length)
> 2) the actual type is obvious (auto x = new MyClass())
> 3) the actual type is huge/untypeable like
> ( Node!(Node!(Node!(Expr!(Terminal!(1),Terminal!(2))))) x = expr!();
> 4) the actual type is unknowable (some template usages)
>
> or
>
> 5) when you're in a real hurry and don't have time to figure out what
> the actual type is. :-)
>
> --bb
More information about the Digitalmars-d-learn
mailing list