Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-01-02 08:29:45


Aleksey Gurtovoy <agurtovoy_at_[hidden]> writes:

> David Abrahams wrote:
>> Aleksey Gurtovoy <agurtovoy_at_[hidden]> writes:
>> > IMO it's more a problem with the layout of template
>> > parameters than with anything else:
>> >
>> > template<
>> > typename T
>> > , typename U = typename metafunction<T>::type
>> > >
>> > class her;
>>
>> That doesn't do anything to reduce the confusability of the 'typename'
>> keyword for me, especially not in Jaap's example:
>>
>> template<
>> typename T
>> , typename T::X N
>> >
>> class foo;
>
> Well, it doesn't confuse me, FWIW.

Does it confuse you to see 'class' there? If not, perhaps you are
just more adept at dealing with overloaded meanings in a local context
than I am. It honestly took me some time to figure out what was going
on when I saw that example come up in this conversation.
>>
>> As I said (and no offense is intended) these seem to be pedantic
>> rather than practical reasons. I suppose you could say "aesthetic"
>> instead of "pedantic",
>
> Yes, and because of the human nature "aesthetic" often has very
> practical consequences. One has to like the code she writes, most of
> the time, anyway. Often the only thing you can do in such situation
> is to change one's perception of one way being more aesthetically
> appealing than the other; e.g. by showing her that, despite being
> "ugly", it's superior from engineering point of view (easier to
> maintain, less error-prone, etc., depending on the context), so,
> then, when writing that "ugly" code, the person will think: "OK, I
> know this is ugly, but I am doing the right thing here, and I am an
> Engineer" :).
>
> We are not close to that state, yet :).

Greg Colvin told me long ago that he almost always uses 'struct',
because it has the right defaults (public/public). I resisted that
idea for many years, but it was planted in my brain and eventually I
got tired of writing

    class X : public Y
    {
     public:
        ...

when

    struct X : Y
    {

would do. I also realized that every extra word or glyph the reader
(usually me) must process has a cost for understandability, and
"class" wasn't communicating more to me than it was costing. There is
also the issue that sometimes I leave out one or more of the 'public'
keywords, and things misbehave for no apparent reason. My eye tends
to filter them out as boilerplate needed to keep the compiler happy,
just like the use of "typename" for dependent types. Finally, the
lines between classes and structs blurred for me as I began to need
various almost-a-C-struct classes, and my resistance crumbled.
Supporting this notational idea that structs and classes are
different, when in fact the compiler doesn't treat them differently,
just seems to come with too much baggage.

[yes, I know about the msvc bug]

Anyway, that's how I reached this sorry, decayed state
w.r.t. class/struct, and I hope it explains why it doesn't bother me
at all to use 'class' in a template parameter list.

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk