auto storage class - infer or RAII?

Jim Hewes jhewesNOSPAM at ix.netcom.com
Tue Nov 14 09:12:55 PST 2006


"Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message 
news:ej6g8l$2g20$1 at digitaldaemon.com...

>
> What I would prefer is if you introduced a new keyword that meant
> "declare". Just that. auto is currently used for type inference not
> because it MEANS "infer the type" but because it's the default storage
> class.
> ...
> Let's say the keyword is chosen to be "def" (being short for "define").


I think this is a good suggestion. Although "infer" is good because it says 
exactly what it's doing, it just sounds a bit odd for a keyword.  I like 
"def" .

I agree with the notion that there should be two different keywords. I think 
"auto" isn't the most descriptive keyword because, as Ary Manzana pointed 
out, "automatic what?". Using "scope" or "local" for RIAA is probable better 
for clarity. But if it had to stay as "auto", it wouldn't be the end of the 
world, either. :)

Regarding the original post:

Walter Bright wrote:
> The auto storage class currently is a little fuzzy in meaning, it can
> mean "infer the type" and/or "destruct at end of scope". The latter only
> has meaning for class objects, so let's look at the syntax. There are 4
> cases:
>
> class Class { }
>
> 1) auto c = new Class();
> 2) auto Class c = new Class();
> 3) auto c = some_expression();
> 4) auto Class c = some_expression();
>
> The ambiguity can be resolved by saying that if auto is used for type
> inference, i.e. cases (1) and (3), then it does not mean RAII. If it is
> not used for type inference, i.e. cases (2) and (4), then it does mean
> RAII.

I'm not sure people would like having to remember this rule every time they 
tried to figure out which variables will have their destructors called. Why 
should explicitly declaring the type of a variable have anything to do with 
whether it's destructor is called? If I decide to modify my code to "turn 
on" type inference, I might inadvertently "turn off" the destructor call. 
Perhaps this came about in an effort to conserve keywords, which is a good 
goal. That's partly why I asked in my other post if type inference is 
important: because most people believe it should require another keyword. If 
you intend to avoid adding another keyword, then perhaps it would be better 
better for type inference be left out rather than to have the "auto" keyword 
overloaded as above. (Not that I'm opposed to type inference; I'm not.)

Jim 





More information about the Digitalmars-d mailing list