Why can't structs be derived from?

Jens jne at somewhere.org
Tue Mar 15 14:46:03 PDT 2011


Jonathan M Davis wrote:
> On Tuesday, March 15, 2011 14:15:48 Max Samukha wrote:
>> On 03/15/2011 10:46 PM, Jens wrote:
>>> Daniel Gibson wrote:
>>>> Am 15.03.2011 21:29, schrieb Jens:
>>>>> Daniel Gibson wrote:
>>>>>> Am 15.03.2011 21:07, schrieb Jens:
>>>>>>> How is it different in D where all polymorphic objects are
>>>>>>> reference types? Take have the design space away, make
>>>>>>> everything a glorified pointer and things are better?
>>>>>>
>>>>>> They obviously are. Successful languages like Java and C# do it.
>>>>>> It's less error-prone and you don't have to worry about
>>>>>> dereferencing stuff all the time (sometimes even multiple
>>>>>> dereferences at once, like in my example).
>>>>>
>>>>> More toward Java-class-language then than C++-level language.
>>>>> Sacrificing stack objects was like throwing out sharp knives from
>>>>> the kitchen. I understand.
>>>>
>>>> If you want value types use structs. Maybe with alias this or
>>>> mixins to "extend" them.
>>>> Or use emplace (see
>>>> http://www.digitalmars.com/d/2.0/phobos/std_conv.html ) with
>>>> classes if you wanna play with sharp tools.
>>>> It's not like you can't (risk to) cut yourself with D, it's just
>>>> easier not to.
>>>
>>> While the above was off-topic, I was alluding to class objects on
>>> the stack. So not to turn the thread into a critique of the entire
>>> language, I'll leave it at that.
>>
>> Class objects are possible on stack in D.
>
> Yes, but only with the help of the standard library:
> std.typecons.scoped. scoped classes are going to be removed from the
> language. It really shouldn't normally be the case that a class
> object is put on the case.
>

And the language-idiomatic things are the ones to focus on rather than 
"it can be done". 




More information about the Digitalmars-d mailing list