OT: on IDEs and code writing on steroids

Lutger lutger.blijdestijn at gmail.com
Tue May 19 23:33:51 PDT 2009


Andrei Alexandrescu wrote:

...
>> What the heck do you need generics for when you have real templates?  To me,
>> generics seem like just a lame excuse for templates.
> 
> I agree. Then, templates aren't easy to implement and they were 
> understandably already busy implementing the using statement.
> 
> Andrei

While I don't fully understand how generics work under the hood in .NET, there are some benefits to how it is done. For example, you can use runtime reflection on generic types. And the jit compiler 
instantiates them at runtime. They may serve a different purpose than templates:

"Anders Hejlsberg: To me the best way to understand the distinction between C# generics and C++ templates is this: C# generics are really just like classes, except they have a type parameter. C++ templates 
are really just like macros, except they look like classes." 

It seems that lack of structural typing is seen as a feature:

"When you think about it, constraints are a pattern matching mechanism. You want to be able to say, "This type parameter must have a constructor that takes two arguments, implement operator+, have this 
static method, has these two instance methods, etc." The question is, how complicated do you want this pattern matching mechanism to be?
There's a whole continuum from nothing to grand pattern matching. We think it's too little to say nothing, and the grand pattern matching becomes very complicated, so we're in- between."  

From: http://www.artima.com/intv/genericsP.html




 











More information about the Digitalmars-d mailing list