Why does D not have generics?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue Jan 12 17:12:11 UTC 2021
On Tuesday, 12 January 2021 at 16:57:43 UTC, Q. Schroll wrote:
> Yes. But I'm not saying: Do exactly as Java does. I'm saying:
> Java has this very interesting concept that D might want to
> learn, too.
Right. D has to chose something that blends well with what is
already there. :-)
But I actually think that the semantics for this are there, but
the syntax is lacking, but maybe I misunderstand what you want.
> For example, if you call T.method(), but no constraint says
> that T.method() exists, the compiler rejects the code. On the
> other hand, in C++ or D, if you call T.method() in a template
> and only test types that happen to have method(), everything is
> good between friends (Andrei's quote).
But I don't quite see how this is different from C++ concepts,
which basically is better syntax for testing traits of types
provided through parameters/methods.
> I'm not arguing you *always* want static checks, obviously DbI
> hardly works that way. All I'm saying is, the big thing
> generics would bring to D is **statically ensuring** that the
> requirements put on type parameters suffice for the
> implementation to be valid.
Yes, I certainly agree that this is desirable. I just don't
understand what semantics are missing. I think D has this? Just
not the syntax?
More information about the Digitalmars-d
mailing list