Hiding class pointers -- was it a good idea?

Gregor Richards Richards at codu.org
Wed Aug 15 09:34:56 PDT 2007


Bill Baxter wrote:
> Gregor Richards wrote:
>> #1 advantage of making them always by-value: Ridiculously inconsistent 
>> use of by-value passing, ref passing and pointer passing.
>>
>> void foo(Thing a);
>> void foo(ref Thing a);
>> void foo(Thing *a);
>>
>> Wait, that's not an advantage at all, that's C++.
> 
> I don't get your point.  Each of those things has different uses in C++.
> 
> // if Thing is small/PoD and you don't want changes to affect caller
> void foo(Thing a);
> 
> // if Thing is bigger, you want to allow caller-visible changes, and you 
>  require calling with non-null
> void foo(ref Thing a);
> 
> // same as above, but you want to allow null too
> void foo(Thing *a);
> 
> 
> The ref-can't-be-null thing may not hold for D, but it's true of C++.
> 
> --bb

This just makes writing code more complicated. It's difficult to 
remember whether some function wants a reference or a pointer, and you 
have to be careful about how you treat them because they're 
fundamentally different (see the operator overloading post). The 
advantage is virtually nil, and it would create this huge complication. 
That's why it's terrible in C++, and that's why it would be terrible in D.

  - Gregor Richards



More information about the Digitalmars-d mailing list