Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-11-02 16:01:02


"Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote
>
>> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:
>>
>>> "Terry G" <tjgolubi_at_[hidden]> wrote
>>>
>>>> I've just finished reading C++ Template Metaprogramming again.
>>>> I just don't get it.
>>>
>>> Should probably not be your first book on template metaprogramming.
>>
>> Really? We designed the book to serve as a complete introduction.
>>
>>> Really, it's just like trying to learn STL without any idea what a
>>> template is.
>>
>> It's not as though the book starts out assuming you know what a
>> metafunction is. What introductory material do you think we missed
>> and should have covered?
>
> Well, it's all about approach to the problem. You present
> metaprogramming as a systematic discipline. Andrei presents it as a
> number of tricks. You define metafunction. Andrei just shows how
> to select between types and implement typelist. For some people
> your approach may be more natural, but I personaly prefer his as far
> as the introduction to the subject is concerned. Once I get a good
> feel of what can be done, and why, then I am ready to talk about
> systematic approach.

Hmm. Bottom-up vs. top-down is always a tension, and people have
different learning styles that are more amenable to one or the other.

We do try to show some simple low-level examples right in the first
chapter (e.g. binary). Admittedly, that's not as useful an example as
some of the things Andrei does with low-level code, but then it's also
a *lot* simpler. We then continue with an actual, useful example of
low-level type selection using specialization in chapter 2. Although
we introduce the general idea of a "metafunction" in the beginning of
chapter 2, we don't really try to define it until long after that
example is complete.

I am not arguing with you; I just want to learn how to serve my
readers better, and so far it doesn't make sense to me. What you seem
to be saying, by analogy, is that you'd want to see a whole book's
worth of material on OO programming in 'C' in order to understand why
the OO paradigm is useful, before reading about how to do it in C++
with real classes.

> Another thing that IMO doesn't help understanding of the material,
> either in the book or in the MPL docs, is the extensive usage of
> lambda. IMO it just adds extra magic to the examples, making one
> feel that he doesn't really understand how things work. I think
> examples with regular metafunction objects would be much easier to
> understand, at least initially.

But we _do_ start with "regular metafunction objects." We don't start
using lambda expressions until after we've shown how to work with
metafunction classes.

>>> IMO, you should really start with template metaprogramming itself,
>>> and then move to MPL. Try Alexandrescu's "Modern C++ design" --
>>> it also contains a lot of examples why you would want to use a
>>> typelist.
>>
>> As great a book as "Modern C++ Design" is, it really surprises me
>> to see it recommended as an introduction to template
>> metaprogramming over "C++ Template Metaprogramming." MC++D is not
>> about specifically TMP, and doesn't even attempt to describe what
>> TMP is. It does contain numerous examples of basic TMP applied to
>> traditional OO design patterns, which I think is the real point of
>> that book, and IMO makes MC++D an ideal follow-on to C++TMP.
>
> Not really, once I read you book I would like to use MPL, right ;-)

Cute. Yes, it would be nice to see a version of MC++D rewritten to
use MPL... but then it would be a much shorter book ;-)

> As for me personally, I read Alexandrescu first, then Czarnecki
> (chapter 10, I think), and then your book. If I had to start now, I
> would use same order -- it works for me -- but I realize that it can
> be different for other people.
>
> To summarize -- I think your book is great for the intermediate to
> advanced metaprogrammers, but as far as beginners are conserned, it
> may not always work. As in the case with the OP.

Granted, it may not always work. I'm still looking for some insight
as to why not.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net