auto storage class - infer or RAII?

Walter Bright newshound at digitalmars.com
Sun Nov 12 03:08:23 PST 2006


Bill Baxter wrote:
> Which is good, since automatic type deduction is basically a 
> typing saving feature to begin with.

No, it's way way more than that. Auto type deduction gets us much closer 
to the goal of the type of something only needs to be specified once, 
and then anything that manipulates it infers the right type. This makes 
code much more robust.

For example,

	auto len = foo.length;

What is the type of foo.length? Is it an int? uint? size_t? class Abc? 
Without type inference, I'd have to go look it up. With type inference, 
I know I've got the *correct* type for i automatically.

Now, suppose I change the type of foo.length. I've got to go through and 
check *every* use of it to get the types of the i's updated. I'll 
inevitably miss one and thereby have a bug.

With automatic type inference, I'm done before I start, and it's done 
correctly. The fewer types one has to specify, the better, and note that 
none of the advantages of static typechecking are lost, either.



More information about the Digitalmars-d mailing list