Hiding class pointers -- was it a good idea?

James Dennett jdennett at acm.org
Sat Aug 18 08:00:54 PDT 2007


Walter Bright wrote:
> James Dennett wrote:
>> Walter Bright wrote:
>>> James Dennett wrote:
>>>> Walter Bright wrote:
>>>>> Value types are fundamentally different from reference types. D gives
>>>>> you the choice.
>>>> C++ gives you *more* choice by allowing easier migration between
>>>> the two without imposing performance or syntactic differences.
>>> That isn't my experience. In my work on DMDscript in D, I changed some
>>> types between struct and class to try out some variations, and found it
>>> to be a lot easier than in C++. For one thing, I didn't have to find and
>>> edit all the -> and .'s.
>>
>> In C++, no, you didn't, as structs and classes are no different
>> in their use of "->" and "." (as you're aware, they're all just
>> classes).
> 
> I meant I switched between value and reference semantics for an object.

Careful with selective quoting!  I recognized that you
probably meant this fundamental change of semantics with
my very next paragraph, reproduced below:

>> Now, if you changed from using objects by value to using them
>> by reference, it would be dangerous to take the D route and use
>> almost the same syntax for both (for example, you inherit the
>> ubiquitous Java bug of writing MyType foo; and finding that foo
>> is null rather than being a usable object).

Similar concept should look similar; similar syntax should
have similar semantics.  You've chosen to use (almost) the
same syntax to mean two very different things, with subtle
gotchas such as the simple but pervasive bug noted above.

-- James



More information about the Digitalmars-d mailing list