Can we just have struct inheritence already?

12345swordy alexanderheistermann at gmail.com
Thu Jun 13 14:53:57 UTC 2019


On Thursday, 13 June 2019 at 07:04:06 UTC, Manu wrote:
> On Wed, Jun 12, 2019 at 11:40 PM Andrei Alexandrescu via 
> Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>
>> On 6/11/19 7:45 PM, Manu wrote:
>> > On Tue, Jun 11, 2019 at 12:35 PM Exil via Digitalmars-d 
>> > <digitalmars-d at puremagic.com> wrote:
>> >> Kind of curious, what do you use a base class for that has 
>> >> no members, is a size of zero, and also has no vtable or 
>> >> virtual functions?
>> >
>> > Metaprogramming; it's a template argument.
>>
>> Subtyping is not needed for metaprogramming. (C++'s awkward 
>> way of doing
>> it overuses it.)
>
> Overuse of `alias this` is not any better. `alias this` is 
> relatively
> much more awkward, and I would say objectively less easy to 
> read and
> understand.
> You can't miss the base at the top of the struct, you know 
> exactly
> where to look for it. With `alias this`, you have to scan the 
> object
> from top to bottom to see if it's there, and then you have to 
> take
> note what object is acting as the base and look for that and 
> where it
> sits relative to other members, and then worry about the 
> zero-size
> hack.
> That alone makes C++'s "awkward way of doing it" look golden, 
> but then
> there's also the issues with the IDE tooling, and that there's 
> only
> one `alias this` slot, which we might need for implicit 
> conversion of
> some sort.
>
> What's so upsetting about C++'s approach? You say 'subtyping', 
> but
> that sounds like you're talking about polymorphism again.
> Perhaps it would be better to say 'extending', which is really 
> what it
> is applied to a struct. I think it's a simple and natural 
> syntax to do
> a simple and natural operation like extending a struct.
>
> Look, I'm not actually married to C++'s approach (if you have a 
> better
> idea), but I'm dreadfully bored of D's shitty approach, I've 
> had a
> decade to try and think it's cool, but I actually think it's 
> more shit
> than I thought it was 10 years ago.
> I used to think it was a cool idea; it's a 'cute' use of a novel
> feature in D which achieves a goal... and like, bugger C++ and 
> it's
> stupid face, and anything that's not like C++ is cool, but I was
> wrong. It's a shitty thing to write over and over again and I 
> hate it,
> having done it **A LOT**.
> I haven't generally made a fuss about this like other things 
> because
> it's not a blocker in any way, but it's important to express 
> how bored
> I am of the pattern. It's not better.

Wouldn't it be better to allow structs to implement static only 
interfaces?

-Alex



More information about the Digitalmars-d mailing list