Slow performance compared to C++, ideas?

Manu turkeyman at gmail.com
Tue Jun 4 17:03:35 PDT 2013


On 5 June 2013 02:21, Rob T <alanb at ucora.com> wrote:

> On Tuesday, 4 June 2013 at 05:58:30 UTC, Andrei Alexandrescu wrote:
>
>> On 6/4/13 1:41 AM, Rob T wrote:
>>
>>> Structs would IMO be far more useful if they had inheritance.
>>>
>>
>> We do offer subtyping via alias this.
>>
>> Andrei
>>
>
> Yeah, I saw that method described in another thread. The technique is not
> even remotely obvious, but the major problem is that it's very limited.
> After you do one alias this, you can't use alias this again for other
> things. Maybe that'll eventually change, I don't know. It seems like a hack
> to me, I'd rather see real inheritance.
>
> On Tuesday, 4 June 2013 at 05:58:58 UTC, Jonathan M Davis wrote:
>
>> How would it even work for a struct to inherit without polymorphism? The
>> whole
>> point of inheritance is to make it so that you can create types that can
>> be
>> used in place of another,
>>
> ....
>
> The other significant reason for inheritance is to reuse pre-built
> sub-components. I rarely use polymorphism, but I make a lot of use out of
> inheritance, so what happens is that I end up creating classes when all I
> really need is structs. I cannot be the only person doing this either, and
> I suspect its very common.
>
>  Use composition, and if you want to be able to call members of the inner
>> struct on the outer struct as if they were members of the outer struct,
>> then
>> use alias this or opDispatch to forward them to the inner struct.
>>
>>
> For simulating inheritance, yes, you probably can make use out of inner
> structs, but how to make it all work seamlessly is not obvious and using
> opDispatch to make it stick together is time consuming and error prone.
>
> On Tuesday, 4 June 2013 at 05:56:49 UTC, deadalnix wrote:
> ...
>
>> struct are value type. You can't know the size of a polymorphic type. So
>> you'll have trouble sooner than you imagine.
>>
>
> That's not an issue if you cut out the polymorphism nonsense from the
> feature set, which means that for structs the size is always knowable. I
> see no reason why structs cannot inherit and unfortunate that D forbids it.
>
> I'd like to hear what Manu says about it, because from what I am reading
> between the lines is that he probably does not need to be using classes but
> cannot use structs because the are too limited - that's my guess, but I
> really don't know. For me, I'd use structs much more often except that they
> cannot inherit.


I certainly have and do write shallow inheritance structures with no
virtuals, it does occur from time to time, and I have missed struct
inheritance in D, but alias this has met my needs so far.
But I'd say the majority of classes are polymorphic. There's usually at
least some sort of 'update()', or 'doWork()' function that needs to be
virtual, but the vast majority of methods are trivial accessors throughout
the hierarchy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130605/9428f94c/attachment.html>


More information about the Digitalmars-d mailing list