auto, var, raii,scope, banana
kris
foo at bar.com
Fri Jul 28 00:58:07 PDT 2006
Andrei Khropov wrote:
> 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.
Someone noted that
x = SomeName();
is confusing, since it doesn't convey whether a class is instantiated,
or a function is called. That's part of the issue noted above, and it
becomes worse when dropping the optional parens
x = SomeName;
Whereas it is still perfectly meaningful when using new instead:
x = new SomeName;
>>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;
> --------------------------------------------------------------
>
Yes, thankyou ~ I'd forgotton about that groovy option:
void main()
{
auto i = 10;
auto foo = new Foo;
scope bar = new Bar;
scope wumpus = new Wumpus;
}
class Foo {}
class Bar {}
scope class Wumpus {} // can only be used as a scope'd instance
More information about the Digitalmars-d
mailing list