What would be the consequence of implementing interfaces as fat pointers ?

John Colvin john.loughran.colvin at gmail.com
Mon Mar 31 02:23:37 PDT 2014


On Monday, 31 March 2014 at 04:48:20 UTC, Manu wrote:
> On 31 March 2014 13:32, Adam D. Ruppe 
> <destructionator at gmail.com> wrote:
>
>> On Monday, 31 March 2014 at 03:25:11 UTC, Manu wrote:
>>
>>> I also feel quite dirty using pointers in D where there is a 
>>> dedicated
>>> reference type available. I don't want * and & to appear 
>>> everywhere in my D
>>> code.
>>>
>>
>> structs can pretty easily be reference types too:
>>
>> struct RefType {
>>    struct Impl {
>>         // put all the stuff in here
>>    }
>>    Impl* impl;
>>    alias impl this;
>>
>>    // add ctors and stuff that new the impl
>> }
>>
>
> And you think this is 'cool'?
> The amount of boilerplate required makes C++ look neat and 
> tidy. You've
> also truncated it significantly.
>
> class RefType
> {
>   // put all the stuff in here
> }
>
>
> Why would anyone want to do all that crap? The reason is to 
> overcome the
> limitations/restrictions of class... so just fix class?
> Or maybe improve struct, so that boilerplate can disappear.
> Perhaps add a distinct ref type like MS did with '^' pointers 
> in WinRT and
> managed C++?
>
> Either way, for my money, that code might appeal to a D nerd 
> (because you
> 'can'!), but I find it acutely distasteful code otherwise.
> No junior programmer would/should understand all that 
> intuitively, and I
> would be embarrassed to show that to a non-D-user that I was 
> trying to
> convince.
>
> If this pattern is recurring (it seems that it is), then I 
> think it's clear
> sign of a chronic deficiency in D. It should probably be 
> studied and
> addressed. I'm seeing it appear a lot.

I think you're missing the point. D is able to create structs 
that work as reference types, as a generic library type. No 
novice programmer or new adopter has to understand how they work 
in order to use them.

I think there should be a more vanilla reference type (than 
NullableRef) in std.typecons in order to address this.


More information about the Digitalmars-d mailing list