What if D would require * for reference types?

Eldar Insafutdinov e.insafutdinov at gmail.com
Mon Jan 18 12:44:36 PST 2010


Denis Koroskin Wrote:

> 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.

I was recently thinking about it as well, but didn't dare to shout things like this. Looks much better to me in terms of consistency. The generic code would benefit from that certainly. I am all for it.

D2 has changed a lot anyway. And it requires conversion as well. This is a good time to make this kind of a radical change.



More information about the Digitalmars-d mailing list