auto, var, raii,scope, banana

Andrei Khropov andkhropov at nospam_mtu-net.ru
Thu Jul 27 16:47:02 PDT 2006


kris wrote:

> Don has a good point: changing to "var" would cause conflict with existing
> variable-names.
> 
> Chad et. al. also have a good point about the conflict regarding static
> opCall() (via the lack of a "new" keyword). I suspect many people find the
> use of "new" to be indicative of allocation, and breaking this consistency
> may have a detrimental effect? Further, it was noted that a missing "new" can
> only be used at the instantiation site -- not at the class decl -- thus, D
> would be losing an existing feature.

Agreed. I also don't think 'missing new' proposal is good.

> 
> I suspect you could count the current number of raii-class uses on a few
> hands, whereas the use of "auto" for implied-type is pretty darned popular --
> and rightly so, since it's really very, very useful. Changing the raii style
> to use a different keyword, whilst retaining implied-type "auto" would be an
> almost imperceptible change?
> 
> 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;
> }

Looks ok to me, but should be in the reverse order I think:

--------------------------------------------------------------
void main()
{
   auto i = 10;
   auto foo = new Foo;
   scope auto bar = new Bar;
   scope auto wumpus = new Wumpus;
}
--------------------------------------------------------------

and with the current D policy of type inference when 'static' or 'const' is
enough for declaration this should be also legal:

--------------------------------------------------------------
   scope bar = new Bar;
--------------------------------------------------------------

-- 
AKhropov



More information about the Digitalmars-d mailing list