Can we just have struct inheritence already?

Manu turkeyman at gmail.com
Tue Jun 11 00:25:15 UTC 2019


On Mon, Jun 10, 2019 at 7:45 AM Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 6/10/19 4:03 AM, Manu wrote:
> > On Mon, Jun 10, 2019 at 12:30 AM Andrei Alexandrescu via Digitalmars-d
> > <digitalmars-d at puremagic.com> wrote:
> >>
> >> On 6/9/19 5:13 PM, Manu wrote:
> >>> This is NOT polymorphism, we're not talking about polymorphism, I wish
> >>> people would not change the topic.
> >>
> >> The problem here is that it's difficult to define subtyping without
> >> polymorphism. C++ does technically allow it, but code such as:
> >>
> >> struct my_vector : public std::vector<int> { ... }
> >>
> >> is universally reviled. I really think it wouldn't help D much to add
> >> struct inheritance.
> >
> > We do it anyway though, it's just terrible.
> > How will it cause any harm to anybody?
>
> The same way it causes in C++. Crack open literally any C++ introductory
> book to find the explanation.

And yet we're doing this anyway... except the code to do it is
obscured, and therefore much more sinister, and prone to accidental
misuse.

> > I hate this idea that something
> > has shown to be sorely missed for so long, and we still can't
> > reconsider it because some moron out there might write bad code?
> > D almost exclusively attracts power-users, who have unbelievably
> > complex software to get on with. Tools are good, especially tools like
> > this which only make a shitty piece of existing language much cleaner
> > and simpler to reason about.
>
> Nonsense. Again: the feature exists in C++ and is explicitly forbidden
> by all coding standards. If they could turn the time back they wouldn't
> have it. So... why would we now imitate it alongside with its mistakes?
> If you have a great idea on how to improve on it, sure. Otherwise, just
> don't.

I mean, supporting `struct Thing : Base` is the obvious idea to
improve it... but that settles that. I'll desist.
TL;DR, we do it all the time and the world hasn't ended. We will keep
doing it. Saying it's bad will not stop us from doing it.
In C++ I've been doing this for like 20 years, and still never
encountered or imagined any sort of issue. Yes, I understand there is
text that says it's bad, I think it's extremely overrated text.
Our code suffers form being noisy and hard to understand at a glance,
and not playing well with the editor/debugger. These things are all
*actual* bad things, and in my opinion, they are MUCH worse things
than the alleged issue that's never caused me a moments harm in my
life (or presumably any of my colleagues who work in the same
codebases...)
There is just no way I could find to balance the risk vs reward
differently. Something that interferes with my work every day, vs some
theoretical issue that's never been a problem in my life...


More information about the Digitalmars-d mailing list