auto storage class - infer or RAII?

Andrey Khropov andkhropov_nosp at m_mtu-net.ru
Sun Nov 12 02:37:40 PST 2006


Bill Baxter wrote:

> "scope" seems a pretty popular suggestion.
> I find it not so bad myself, but I would prefer "scoped" because it's less
> ambiguious.  "scope" makes sense if you think of scope as a verb (scope this
> variable), but just seeing it outside of a sentence it looks like a noun
> (this variable is a scope -- huh?), simply because 'scope' isn't used as a
> verb very often in English.
> 
> 'scoped' is clearly an adjective, as in 'this variable is scoped'. 

Yes I also thought of 'scoped'. Sounds like a good idea to me.
But I can live with 'scope' or 'var' as well.

I don't like the original proposal

'auto x = ClassName(...)' // type inference, new object, RAII 

because sometimes it is hard to distinguish between ClassName (i.e. new object
is created) and FunctionName (it's returned)

With 'scoped' it's clear:

1) auto a = new A();      // type inference, new object, no RAII
2) scoped a = new A();    // type inference, new object, RAII
3) auto a = SomeFunc();   // type inference, object returned from func, no RAII
4) scoped a = SomeFunc(); // type inference, object returned from func, RAII

and of course longer form should be also possible:

'scoped A a = new A();' // RAII, no type inference

> And being
> an adjective puts it in good company with most of the other storage classes
> which are also adjectives: (abstract, auto(matic), const(ant), deprecated,
> extern(al), final, static, synchronized).  
> The only non-adjective storage
> class is 'override'.  I have no idea why it's not "overridden".

I think because 'overridden' is too long to type.
I also think "lock(x)" could be better than "synchronized(x)" for the same
reason.

-- 
AKhropov



More information about the Digitalmars-d mailing list