Random thought: Alternative stuct
Paul Backus
snarwin at gmail.com
Tue Sep 4 04:24:04 UTC 2018
On Tuesday, 4 September 2018 at 04:03:19 UTC, Mike Franklin wrote:
> There are also a few additional differences. classes can
> inherit implementations, but using the technique illustrated in
> https://theartofmachinery.com/2018/08/13/inheritance_and_polymorphism_2.html, you can get something very much like classes. With `alias this` and multiple-`alias this` (https://github.com/dlang/dmd/pull/8378) it gets even better.
>
> [...]
>
> In my opinion, we shouldn't add a third option. Rather, we
> should deprecate classes, and make and expand the capabilities
> of structs. Languages like Zig and Rust have done away with
> classes and all runtime overhead that accompanies them, and are
> showing great promise by expanding on structs with much more
> composable features.
You can implement inheritance in C, if you really want to, but
doing it by hand is far less productive and far more error prone
than using a compiler that does it for you.
Now, with D's metaprogramming capabilities, it may well be
possible to implement an object system as a library, using only
structs. Without AST macros, though, a library solution is always
going to have uglier syntax and worse error messages than a
language feature with compiler support.
If D didn't have built-in OOP features already, it'd be an
interesting question, but given that it does, I think getting rid
of them is a clear net-negative.
More information about the Digitalmars-d
mailing list