|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-01-02 02:01:20
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.
>
> > In short, my motivation for using 'typename's here is that
> > I perceive the 'class' keyword as rather high-weight, semantically
> > loaded, and prefer to use it in its only original context - that
> > is, for declaring/defining a user-defined type that is more than
> > a POD. Using it in other places cheapens the word.
>
> 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 :).
> but the practical consequences of those choices
> outweigh the aesthetic ones for me,
For some reason the cited problems with using 'typename' in the template
parameter lists don't really ring a bell for me. May be it's just me, or may
be it's just you :). To know for sure we would need a "'typename' experience
survey" :).
> especially because in a
> metaprogramming context we will commonly use "struct" instead of
> "class"... once again because the practical consequences outweigh the
> aesthetic ones ;-)
No, that's not the reason, at least not mine :). The practical consequences
do not outweigh the aesthetic ones, they are on the same side, here. Even if
classes by default provided 'public' access to their members, so instead of
template< typename T >
class identity
{
public:
typedef T type;
};
one could write
template< typename T >
class identity
{
typedef T type;
};
I still would be using 'struct' there, because 'identity' has nothing to do
with the loaded OO-centric 'class' meaning at all.
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk