What if D would require * for reference types?
Denis Koroskin
2korden at gmail.com
Mon Jan 18 07:08:34 PST 2010
You know, I'm not usually a guy who proposes radical changes to the
language. I like the way D is, but there are a few proposals that keep
popping up once in a while without a good rationale, and this simple idea
stroke my head solves many of the issues that were found in previous
proposals, so I decided to share it with you.
It's as simple as that: require '*' to denote reference type. What does it
give?
1) Consistency between classes and structs:
Struct* s = new Struct();
Class* c = new Class();
It allows easier transition between classes and structs (please note that
I don't propose any changes to class semantics):
Foo* f = new Foo(); // works for both classes and structs
2) .sizeof consistency, get rid of __traits(classInstanceSize, Foo)
(deprecate in favor of Foo.sizeof):
Foo* f = cast(Foo*)malloc(Foo.sizeof); // works for both classes and
structs (and enums, unions, etc)
f.__ctor(args);
3) No more issues with tail-const, tail-shared, tail-immutable; deprecate
Rebindable (this one was recently discussed):
shared(Foo)* foo; // local pointer to shared type, works for both classes
and structs
Please note that we get these bonuses by only enforcing '*' to denote
refence type, not a huge change to compiler IMO. It *will* break existing
code, but the fix is rather trivial.
To be continued.
More information about the Digitalmars-d
mailing list