Java-like generics in D
Robert Fraser
fraserofthenight at gmail.coim
Sun Aug 12 11:06:08 PDT 2007
Frank Benoit Wrote:
> As addition to the existing templates, i think java like generics would
> be very helpful for D.
>
I think that's an interesting, but wholly unnecessary idea. Generics were added to Java because first-class templates were an impossibility given the bytecode structure. They're a workaround, not a feature to be emulated in other languages.
> Advantages:
> 5) "lightweight templates", because of no more object code duplication
> for new instantiations.
Is object code duplication a huge problem? Are you running into all sorts of code bloat in your projects? D programs _do_ tend to wax a little on the large side, but code bloat is hardly the primary factor of this.
> 6) the compiler can generate the object code independantly of the
> intantiation code
How is this different from #5?
> 7) no more errors like 'forward reference' for generic, because the
> generic can compile without the knowledge of the exact types.
>
there's the one major advantage you've cited, but I don't thin we need a language feature as a workaround for a bug.
> Does that make sense?
>
I get the feeling they would be generally unused and woefully underpowered compared to templates. Look at the uses for generics in Java: almost exclusively in collections and wrapper classes. I've written maybe two generic classes I can think of, their extensibility to user code is limited. D's templates can do _so_ much more.
More information about the Digitalmars-d
mailing list