Can we just have struct inheritence already?

Manu turkeyman at gmail.com
Tue Jun 11 23:45:09 UTC 2019


On Tue, Jun 11, 2019 at 12:35 PM Exil via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Tuesday, 11 June 2019 at 18:19:05 UTC, Manu wrote:
> > On Tue, Jun 11, 2019 at 1:00 AM Walter Bright via Digitalmars-d
> > <digitalmars-d at puremagic.com> wrote:
> >>
> >> On 6/11/2019 12:06 AM, Manu wrote:
> >> > On Mon, Jun 10, 2019 at 11:30 PM Walter Bright via
> >> > Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> >> >>
> >> >> On 6/9/2019 10:52 PM, Manu wrote:
> >> >>> That is indeed the feature that necessitates my 'solution',
> >> >>
> >> >> Is it specifically for C++ interop,
> >> >
> >> > It occurs frequently in C++ interop, but that's only because
> >> > most of
> >> > my code exists in C++.
> >> > I do, and will continue to use base structs in C++ and in D
> >> > for
> >> > exactly the same reasons.
> >> > Every codebase I have ever worked in uses base struct's to
> >> > DRY
> >> > liberally, thousands of engineers think this is fine, and
> >> > I've never
> >> > heard anyone think it's unusual, or weird/problematic.
> >> >
> >> >> or you just want the zero size?
> >> >
> >> > A zero size solution removes the static if hack, but it
> >> > doesn't remove
> >> > the alias this hack. I want to remove both hacks.
> >> > I can't stress enough that struct inheritance exists, it's
> >> > extremely
> >> > common, and we will continue to do it as a completely normal
> >> > practice
> >> > with no apology.
> >> > Please don't make our code ugly and unnecessarily difficult
> >> > to
> >> > understand for no reason.
> >> >
> >> > If you fear misunderstanding with polymorphism, fear not;
> >> > this is not C++, struct is strictly a value type, there is
> >> > no vtable, no virtual, no override, etc... there would be
> >> > compile errors at every turn if anyone ever confused struct
> >> > inheritance for polymorphism. We have a HUGE advantage
> >> > here...
> >>
> >> Can I ask again, in a different way, why do you need the 0
> >> size?
> >
> > To handle base structs with no members.
>
> 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.
It might be the case that some method is expected to exist, but the
particular implementation may or may not require any data.

Virtuals are dead man, nobody uses OOP anymore. It's all about
contracts and things like that.
Base classes might be expected to have a method, and there may be a
static assert to prove that some API is satisfied, but the
implementation may want to have some additional state.
This pattern doesn't exclusively apply to inheritance, but that's the
case on trial.


More information about the Digitalmars-d mailing list