OT: on IDEs and code writing on steroids
dsimcha
dsimcha at yahoo.com
Wed May 20 13:29:38 PDT 2009
== Quote from Yigal Chripun (yigal100 at gmail.com)'s article
> Andrei Alexandrescu wrote:
> > Lutger wrote:
> >> 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
> >
> > Oh, so Wal^H^H^Ha friend of mine I was talking to was right: there's
> > some missing of the point point going on. The code generation aspect of
> > templates is a blind spot of the size of Canada.
> >
> > Andrei
> I think you miss the point here.
> Generics and code generation are two separate and orthogonal features
> that where conflated together by C++.
> while you can do powerful stuff with templates it smells of trying to
> write Haskel code with the C pre-proceesor.
> if you want to see a clean solution to this issue look at Nemerle.
> essentially, their AST Macro system provides multi-level compilation.
> c++ templates are a horrible hack designed to ween off C programmers
> from using the pre-processor and the D templates provide mostly cosmetic
> changes to this. they do not solve the bigger design issue.
Not sure I agree. C++ templates were probably intended to be something like
generics initially and became Turing-complete almost by accident. To get Turing
completeness in C++ templates requires severe abuse of features and spaghetti code
writing. D extends templates so that they're actually *designed* for
metaprogramming, not just an implementation of generics, thus solving C++'s design
problem. Mixins (to really allow code generation), CTFE (to make it easier to
generate code), static if (to avoid kludges like using specialization just to get
branching) and tuples (to handle variadics) make D templates useful for
metaprogramming without massive kludges.
More information about the Digitalmars-d
mailing list