auto, var, raii,scope, banana

Kirk McDonald kirklin.mcdonald at gmail.com
Thu Jul 27 11:55:49 PDT 2006


kris wrote:
> Thus, it would appear to make sense to retain "auto" for implied-type, 
> and introduce something *else* for automatic cleanup at end-of-scope 
> (and also as a class attribute). how about reusing the "scope" keyword?
> 
> void main()
> {
>   auto i = 10;
>   auto foo = new Foo;
>   auto scope bar = new Bar;
>   auto scope wumpus = new Wumpus;
> }

I've argued in the past about being able to elide the 'new' keyword 
entirely. I like the Python semantics, where 'calling' a class is 
synonymous with calling a factory function that returns instances of the 
class. The 'new' keyword is just redundant... until you remember that D 
has static opCall.

So, without imposing an arbitrary restriction of disallowing static 
opCall for classes (but not for structs!), or saying e.g. that you have 
to say "new" for any class with static opCall defined for it (which 
would just be a huge headache)... I think this is the best solution.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki



More information about the Digitalmars-d mailing list