Can we just have struct inheritence already?

Manu turkeyman at gmail.com
Sun Jun 9 22:13:51 UTC 2019


On Sun, Jun 9, 2019 at 3:05 PM Manu <turkeyman at gmail.com> wrote:
>
> On Sun, Jun 9, 2019 at 2:50 PM Ola Fosheim Grøstad via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
> >
> > On Sunday, 9 June 2019 at 21:35:19 UTC, Ola Fosheim Grøstad wrote:
> > > On Sunday, 9 June 2019 at 21:13:50 UTC, Manu wrote:
> > >> This is NOT polymorphism, we're not talking about
> > >> polymorphism, I wish people would not change the topic.
> > >
> > > Well, it sort of is. Consider a situation where you have
> > > assignment defined for the super class, and where there is a
> > > field in the subclass that depends on a field in super.
> >
> > Or rather: you sometimes have a dependency, then you want the
> > type system to prevent assignments through the base class.
> > However, in other cases you don't have a dependency, then you do
> > want to be able to assign through the base class.
> >
> > But you need something syntactical to tell the type system that
> > such dependencies exist.
>
> Such a dependency reeks of polymorphism-proper, maybe you're using the
> wrong tool?
> Anyone can write bad code... if your code is brittle in that way, then
> you'll find out soon enough when someone does that!
> It might also be impossible to inhibit direct assignment of the base.
> There may be some practical limitations that we can design that make
> such mistakes relatively less unlikely or easy to catch.

And here's the thing... this code ALREADY EXISTS in effect, except
that it's way more hideous, and pointlessly aggravated (for the list
of reasons above)!

There's a difference when something seems annoying once or twice, and
when it's been consistently annoying for 10 years with no sign that
patterns that leads to the situation are likely to change.
The errors and issues that the pattern in my OP cause, undoubtedly
outweigh any "but I thought of a gotcha!" you can think of... because
every such gotcha is already deployed, and coupled with the entire
experience being so much worse.



More information about the Digitalmars-d mailing list