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

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Mar 10 15:49:46 PST 2006


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.

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.) 





More information about the Digitalmars-d mailing list