Templates everywhere
Philippe Sigaud
philippe.sigaud at gmail.com
Sun Mar 14 15:20:33 PDT 2010
On Sun, Mar 14, 2010 at 21:29, Walter Bright <newshound1 at digitalmars.com>wrote:
> Philippe Sigaud wrote:
>
>> 1- thanks Walter for opening new vistas to me. Doing templated code
>> in D is so fun and powerful that you transformed forever the way I
>> look at problems.
>>
>
> Years ago, although I had implemented templates for C++, I didn't "get"
> them. Not at all. I didn't even plan to put templates in D, because they
> seemed overly complex, ugly, and had little value.
>
That's interesting to know that you could implement templates, without
understanding them.
I eventually realized that what was preventing me from understanding C++
> templates was the syntax. Change the syntax, and what is happening suddenly
> becomes obvious.
> (snip)
> Yes, it looks like a trivial change, and perhaps it is. But it makes a
> world of difference, because it now looks like something I do get - a
> parameter list to something.
>
That's my first 15' with D right there, Walter.
It may be due to my not knowing what 'template' means in English at the time
I was exposed to them in C++. But reading the D docs, it became clear that
they were just 'potential code', waiting to be created, with parameters
governing what could happen.
> I had another epiphany from watching Scott Meyers give a presentation about
> an application for templated type lists in C++. Nearly the full hour was
> spent detailing a titanic struggle with the syntax. I suddenly realized that
> the whole presentation would have been over in 5 minutes if the syntax of
> type lists was simply that of an array of types. We already understand
> arrays of values, so why should an array of types be any different?
>
Seconded, and thanks again for making that accessible.
I was looking at Boost MPL (Meta-Programming Library) a few days ago, and
thinking "How complicated the C++ syntax makes all this". I consider the MPL
one of the most impressive part of Boost, but I don't think I'll ever use
it. I have trouble extracting the intent among all the syntactic noise.
Whereas in D, the first time I read some of Andrei's templates, (something
akin to staticMap!(Unqual, Types)) the meaning was clear.
The third 'leg' on which D templates rest is the alias parameters. I can
have access to any symbol, including other templates? Oh yes!
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100314/02f83324/attachment.html>
More information about the Digitalmars-d
mailing list