I don't like auto. (the auto-typing I mean)

Ameer Armaly ameer_armaly at hotmail.com
Fri Mar 10 18:15:50 PST 2006


"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
news:dut3aq$2vlp$1 at digitaldaemon.com...
> More and more I see D code strewn with
>
> auto someVariable = someExpression();
>
> I don't like this.  A bit.
>
> Everyone seems to be treating auto like it's the best damn thing to come 
> out in the language in a long time.  Now in some cases, it's really 
> obvious what the type is, and sometimes saves a lot of typing:
>
> auto w = new ClassName();
> auto x = SomeReallyLongClassName.EnumType.Value;
> auto y = SomeReallyUglyTemplate!(with, three, arguments);
>
> That's cool.
>
> But is this really necessary:
>
> auto z = 5;
>
> Do I know what z is?  Not really.  I have to look up the integer literal 
> deduction rules to find out.  It's an int, but what about when the 
> literals get bigger?  Are you so sure what type it is?
>
> And then there's things like
>
> auto fork = someFunction();
>
> Oh boy.  What type is it now?  I have to look up someFunction in the docs, 
> or if there are no docs, in the code itself.  What module was someFunction 
> in again?  Hmm....  where is it...  wasted time.
>
I really think this comes down to a matter of common sense; people who want 
to write readable code will use auto only when it's necessary; in my opinion 
that's not too often.
> Since this undeniably has some use, I can't say get rid of it.  But could 
> we practice some restraint?  I'd say don't use auto unless it's really 
> obvious what type the variable is.
>
> (And by the way, I think it's dumb that it's called auto and also think it 
> should be called var.)
>
I agree that it shouldn't be called auto (auto what?) but var doesn't seem 
to sound right either; it may come down to guess-the-keyword. 





More information about the Digitalmars-d mailing list