Opportunity
Walter Bright
newshound2 at digitalmars.com
Tue Apr 9 20:57:07 PDT 2013
On 4/9/2013 1:17 AM, Russel Winder wrote:
> I have yet to find anyone who can tell me why Go must have generics with
> a cogent argument that makes sense to me.
I was strongly opposed to generics for a long time, but finally changed my mind.
One thing I learned about templates from Andrei and Scott Meyers is that one can
write programs that manipulate types. For example, for a variadic function an
array of types represents the types of the actual arguments. This can then be
used to create a typesafe printf, which is what we have in std.stdio.
Another thing we can do with templates that is hard to imagine doing with other
means is the compiler's hook into making a precise GC. In object.d, there's a
template named RTInfo(T). For each call to new(), the compiler passes along a
static value generated by RTInfo!T, where T is the type of the data being allocated.
What this means is the compiler (and language) needs NO KNOWLEDGE of what the GC
needs. The library implementer is free to innovate whatever kind of tables are
necessary. It means that radically different GCs can be built and swapped in and
out without change to the compiler or language. It means that anyone who wants
to build a better GC can do so without forking the compiler.
More information about the Digitalmars-d
mailing list