auto storage class - infer or RAII?

Walter Bright newshound at digitalmars.com
Sun Nov 12 13:48:16 PST 2006


Bill Baxter wrote:
>  From a software maintenance and robustness standpoint I think that cuts 
> both ways.  If I don't know the type then it's easy to do something 
> wrong with it like
> 
>    auto len = foo.length;
>    len = -1;  // oops! len is unsigned!  not what I intended!

If you wrote:

	int len = foo.length;

and foo.length was unsigned, isn't that just another sort of bug?

>  From the point of view of someone reading and maintaining code, I hope 
> the only places I see auto are where the type is obvious from the 
> context, like auto foo = new SomeClassWithALongNameIDontWantToTypeTwice.

I see it as much more useful than that.

> I think it's bad practice to use auto just becuase you're too lazy to go 
> figure out what the right type is.  If you don't figure it out when 
> writing it, then every person after you reading or maintaining the code 
> is going to have to go figure it out.

Not necessarily. Think of it like writing templates that depend on a 
generic type T and assume certain properties of that type.



More information about the Digitalmars-d mailing list