Can we just have struct inheritence already?

XavierAP n3minis-git at yahoo.es
Mon Jun 24 21:13:17 UTC 2019


On Monday, 24 June 2019 at 16:13:05 UTC, bioinfornatics wrote:
>
> Thanks for your insight.
> So I have a question what solve the struct inheritance which 
> can not be done by the use of method forwarding?

Less typing (cleaner, better code) and subtyping/polymorphism.

Of course every language feature could be implemented from 
scratch in C. But if we're using other languages it's because 
their features are useful.

> To me the template proxy is the way to go. They are no needs to 
> extend the dlang syntax.
>
> Case 1: too few people know it
> Case 2: struct inheritance solve things that can not be done 
> using the proxy
>
> https://dlang.org/library/std/typecons/proxy.html

Proxy behaves (is purposely designed to behave) quite differently 
from inheritance... But to answer the general proposition that 
it's best to eliminate inheritance and implement it from 
templates, I think it makes no sense in principle because 
templates are more complex, both in code and under the hood (of 
the compiler specially). Inheritance (without virtual/dynamic 
dispatch) is as simple as aligning a few bytes together with the 
base type's ones.

There are fads in patterns, and nowadays people are against 
inheritance. Little ago templates were the answer to everything, 
just like OOP was in the 90s (of course templates are extremely 
useful). Their use pushed compilation times and code readability 
out of orbit. Nowadays quite some people are reacting by going 
back to C, plain composition, and their dogma is that dangling 
pointers are the least problem.

D was purposely created not to follow one single paradigm, but to 
offer all modern, proven ones to discerning programmers.


More information about the Digitalmars-d mailing list