Auto syntax revisited

S. Chancellor dnewsgr at mephit.kicks-ass.org
Mon Feb 20 15:55:29 PST 2006


While I agree with your sentiment.  However, I think local associated 
with the reference is confusing as it leads people to believe it is 
somehow different from "global." (See Python's usage of these keywords) 
This would make much more sense associated with the object, like Sean 
kelly mentioned.  However, there is still problems with that.

While we're coming to a consensus on these things, let us fix the reuse 
of static, and the !is keyword as well.

-S.


On 2006-02-20 12:23:26 -0800, Fredrik Olsson <peylow at gmail.com> said:

> After some discussion on #d I though why not put my thoughts into more 
> permanent writing.
> 
> Keyword auto is used for two reasons; implicit type and making sure the 
> object is destroyed when going out of scope. I suggest a new keyword 
> for the latter: local.
> 
> local auto foo = new Bar();
> 
> Why? First of auto is only used for the implicit type, so no confusion. 
>   The keyword local in itself describes pretty to the point what is 
> supposed to happen with the variable. And nothing is said about the 
> stack, so we are future proof if in the future we would like to also 
> have:
> 
> local auto foo = Bar();
> 
> Where Bar(); is a function returning an Object, but we still want the 
> object to be destructed when going out of this scope. The 
> implementation is quite different as the Object would need to be on 
> heap, but the syntax is the same. So local would indicate what should 
> be done (destroy when out of scope), not how it should be done 
> (allocate on stack or whatever).
> 
> Even this could be possible, without syntax changes:
> {
>    local Foo bar;
>    // some code
>    Baz(bar); // Jupp Baz have a inout parameter returning an object.
> } // And bar is still destroyed if set to something here...
> 
> 
> regards
> // Fredrik Olsson





More information about the Digitalmars-d mailing list