I don't like auto. (the auto-typing I mean)
Hasan Aljudy
hasan.aljudy at gmail.com
Fri Mar 10 16:15:59 PST 2006
Jarrett Billingsley wrote:
> 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.)
>
>
Yeah. auto can make things very confusing.
I've been using it only because I'm too lazy to type some long class name.
It doesn't help readability at all!! I sometimes forget what the type is
supposed to be when I read code that I've written myself.
More information about the Digitalmars-d
mailing list