DI File Generation

Paulo Pinto pjmlp at progtools.org
Wed Dec 14 22:56:44 PST 2011


Sorry, but that is not correct.

I don't know if that is your case, but many people confuse generics with the dumb implementation that Java has.

The languages that support proper generics, have the compiler store a kind of code template in the module with placeholders. This code is then extracted from the module during compile time and the placeholders get replaced by the code required for the specific type.

One reason why the C++ templates are the way they are, is that C++ designers always wanted to support the primitive compiler/linker toolchains in UNIX. This is not an issue in languages that have proper module support without toolchain constraints.

--
Paulo


Jonathan M Davis Wrote:

> On Thursday, December 15, 2011 00:26:05 Paulo Pinto wrote:
> > Am 14.12.2011 21:13, schrieb Jonathan M Davis:
> > >> Also, _all_ templated _anything_ has to be put in the .di file, and a
> > >> lot of> 
> > > stuff tends to be templated in D (especially in the standard library),
> > > so it's pretty easy to need to put a large portion of your code in the
> > > .di file anyway.
> > I think that Modula-3, Eiffel and Ada don't have issues with having
> > "template" declaration in the interface part, with the definition being
> > done in the implementation part.
> > 
> > Then again, what they support is what is more commonly known as generics.
> > 
> > I imagine you mean that metaprogramming requires the template code to be
> > in the .di file as well, right?
> 
> As similar as they may appear, templates and generics are completely different. 
> With templates, you're literally generating code, and the compiler needs to 
> full source of the template to generate that code. Generics typically means 
> that you have one set of code which is just used with different types 
> (typically enabled by the fact that all of the type have a base class which 
> they share). So, with generics, you can separate interface and implementation, 
> but that's impossible with templates (C++ has the same issue). The code which 
> is generated could vary drastically depending on what you try and instantiate 
> a template with, unlike with generics. And ultimately, what it comes down to 
> is the fact that templates literally generate code, so their full source is 
> required.
> 
> - Jonathan M Davis



More information about the Digitalmars-d mailing list