Why being an indifferent typist may be harmful

Discussion in 'C++' started by Steven T. Hatton, Oct 20, 2004.

  1. On page 858 of TC++PL(SE) Dr. Stroustrup states the following:
    <quote>
    The /typename/ keyword can also be used as an alternative to /class/ in
    template declarations:

    template<typename T> void f(T);

    Being an indifferent typist and always short on screen space, I prefer the
    shorter:

    template<class T> void f(T);
    </quote>

    Consider now the discussion in _C++ Templates_ on page 51:

    <quote>
    As usual, instead of *typename* you could use the keyword *class* for
    template parameters. However, *CONT* is used to define a class and must be
    declared by using the keyword *class*....
    </quote>

    We are already in the realm of discussing the template parameters of
    template template parameters. That is sufficiently beguiling on its own
    without the introduction of even more subtle semantic hair-splitting. I
    argue that using /typename/ everywhere it is meaningful, and
    reserving /class/ for the instances where it it necessary lends clarity to
    the code. The alternative merely saves keystrokes at the expense of
    clarity.

    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
    Steven T. Hatton, Oct 20, 2004
    #1
    1. Advertising

  2. Steven T. Hatton wrote:
    > On page 858 of TC++PL(SE) Dr. Stroustrup states the following:
    > <quote>
    > The /typename/ keyword can also be used as an alternative to /class/ in
    > template declarations:
    >
    > template<typename T> void f(T);
    >
    > Being an indifferent typist and always short on screen space, I prefer the
    > shorter:
    >
    > template<class T> void f(T);
    > </quote>
    >
    > Consider now the discussion in _C++ Templates_ on page 51:
    >
    > <quote>
    > As usual, instead of *typename* you could use the keyword *class* for
    > template parameters. However, *CONT* is used to define a class and must be
    > declared by using the keyword *class*....
    > </quote>



    I couldn't find the quote above. Also it doesn't make sense. May you
    provide more info?




    > We are already in the realm of discussing the template parameters of
    > template template parameters. That is sufficiently beguiling on its own
    > without the introduction of even more subtle semantic hair-splitting. I
    > argue that using /typename/ everywhere it is meaningful, and
    > reserving /class/ for the instances where it it necessary lends clarity to
    > the code. The alternative merely saves keystrokes at the expense of
    > clarity.



    That's is a "religious" discussion and such a conversation can not reach
    any reasonable conclusion.


    However thinking that a class is a user defined type, the keyword class
    in template definitions makes sense to me.


    In any case, use whatever fits you better.



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Oct 20, 2004
    #2
    1. Advertising

  3. Ioannis Vranos wrote:

    > Steven T. Hatton wrote:
    >> On page 858 of TC++PL(SE) Dr. Stroustrup states the following:
    >> <quote>
    >> The /typename/ keyword can also be used as an alternative to /class/ in
    >> template declarations:
    >>
    >> template<typename T> void f(T);
    >>
    >> Being an indifferent typist and always short on screen space, I prefer
    >> the shorter:
    >>
    >> template<class T> void f(T);
    >> </quote>
    >>
    >> Consider now the discussion in _C++ Templates_ on page 51:
    >>
    >> <quote>
    >> As usual, instead of *typename* you could use the keyword *class* for
    >> template parameters. However, *CONT* is used to define a class and must
    >> be declared by using the keyword *class*....
    >> </quote>

    >
    >
    > I couldn't find the quote above. Also it doesn't make sense. May you
    > provide more info?
    >
    >
    >
    >
    >> We are already in the realm of discussing the template parameters of
    >> template template parameters. That is sufficiently beguiling on its own
    >> without the introduction of even more subtle semantic hair-splitting. I
    >> argue that using /typename/ everywhere it is meaningful, and
    >> reserving /class/ for the instances where it it necessary lends clarity
    >> to
    >> the code. The alternative merely saves keystrokes at the expense of
    >> clarity.

    >
    >
    > That's is a "religious" discussion and such a conversation can not reach
    > any reasonable conclusion.
    >
    >
    > However thinking that a class is a user defined type, the keyword class
    > in template definitions makes sense to me.
    >
    >
    > In any case, use whatever fits you better.
    >
    >



    The first quote is from the big white book on page 858. It is the final
    paragraph of §C.13.5:
    C++ Programming Language, The: Special Edition, 3rd Edition
    http://www.research.att.com/~bs/3rd.html

    The second quote is from the book with the blocks on the cover. It is the
    first full paragraph on page 51 in §5.4:

    C++ Templates - The Complete Guide
    http://www.josuttis.com/tmplbook/

    Before I attempt to explain more fully, please verify that you are looking
    at the same resources as I am referring to.
    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
    Steven T. Hatton, Oct 20, 2004
    #3
  4. Steven T. Hatton wrote:

    > The first quote is from the big white book on page 858. It is the final
    > paragraph of §C.13.5:
    > C++ Programming Language, The: Special Edition, 3rd Edition
    > http://www.research.att.com/~bs/3rd.html
    >
    > The second quote is from the book with the blocks on the cover. It is the
    > first full paragraph on page 51 in §5.4:
    >
    > C++ Templates - The Complete Guide
    > http://www.josuttis.com/tmplbook/
    >
    > Before I attempt to explain more fully, please verify that you are looking
    > at the same resources as I am referring to.



    Yes I thought the last was from TC++PL too (the template chapter or
    something). I do not have the "C++ templates" book and the "*CONT*" word
    also did not make sense too me.


    Anyway, I said what I think on the subject. :)



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Oct 20, 2004
    #4
  5. Ioannis Vranos wrote:

    > Yes I thought the last was from TC++PL too (the template chapter or
    > something). I do not have the "C++ templates" book and the "*CONT*" word
    > also did not make sense too me.
    >
    >
    > Anyway, I said what I think on the subject. :)


    The example in question can be found here:
    http://www.josuttis.com/tmplbook/
    http://www.josuttis.com/tmplbook/basics/stack7.hpp.html
    basics/stack7.hpp

    Note that the use of the /class/ key word is not optional here. It cannot
    be substituted with /typename/:

    template <typename T, template <typename> class CONT>
    void Stack<T,CONT>::push (T const& elem)
    {
    elems.push_back(elem); // append copy of passed elem
    }

    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
    Steven T. Hatton, Oct 20, 2004
    #5
  6. Steven T. Hatton wrote:
    > [...]
    > We are already in the realm of discussing the template parameters of
    > template template parameters. That is sufficiently beguiling on its own
    > without the introduction of even more subtle semantic hair-splitting. I
    > argue that using /typename/ everywhere it is meaningful, and
    > reserving /class/ for the instances where it it necessary lends clarity to
    > the code. The alternative merely saves keystrokes at the expense of
    > clarity.


    You should go argue that in comp.std.c++, please. The Standard requires
    'class' in some places and allows 'typename' to replace it in others. It
    is not done to confuse people. If it confuses you, there are two ways to
    resolve that: apply some effort and learn it, or apply some effort and
    change it. The former happens in your head, the latter in comp.std.c++.

    V
    Victor Bazarov, Oct 20, 2004
    #6
  7. Steven T. Hatton wrote:

    > The example in question can be found here:
    > http://www.josuttis.com/tmplbook/
    > http://www.josuttis.com/tmplbook/basics/stack7.hpp.html
    > basics/stack7.hpp
    >
    > Note that the use of the /class/ key word is not optional here. It cannot
    > be substituted with /typename/:
    >
    > template <typename T, template <typename> class CONT>
    > void Stack<T,CONT>::push (T const& elem)
    > {
    > elems.push_back(elem); // append copy of passed elem
    > }




    Yes however CONT *is* a class (and not an int for example).



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
    Ioannis Vranos, Oct 20, 2004
    #7
  8. Victor Bazarov wrote:

    > Steven T. Hatton wrote:
    >> [...]
    >> We are already in the realm of discussing the template parameters of
    >> template template parameters. That is sufficiently beguiling on its own
    >> without the introduction of even more subtle semantic hair-splitting. I
    >> argue that using /typename/ everywhere it is meaningful, and
    >> reserving /class/ for the instances where it it necessary lends clarity
    >> to
    >> the code. The alternative merely saves keystrokes at the expense of
    >> clarity.

    >
    > You should go argue that in comp.std.c++, please. The Standard requires
    > 'class' in some places and allows 'typename' to replace it in others. It
    > is not done to confuse people.


    The situation exists because of historical accident. The use of /class/ to
    signify template parameters preceeded the introduction of the /typename/
    keyword.

    > If it confuses you, there are two ways to
    > resolve that: apply some effort and learn it, or apply some effort and
    > change it. The former happens in your head, the latter in comp.std.c++.


    There is of course a third approach. That is to discuss issues of style
    with other programmers and try to establish conventions. That, according
    to the FAQ for this newsgroup, is properly discussed here.
    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
    Steven T. Hatton, Oct 20, 2004
    #8
  9. Steven T. Hatton

    JKop Guest


    > template <typename T, template <typename> class CONT>
    > void Stack<T,CONT>::push (T const& elem)
    > {
    > elems.push_back(elem); // append copy of passed elem
    > }



    Haven't a clue what's going on!


    -JKop
    JKop, Oct 20, 2004
    #9
  10. Steven T. Hatton wrote:

    > Victor Bazarov wrote:
    >
    >
    >>Steven T. Hatton wrote:
    >>
    >>>[...]
    >>>We are already in the realm of discussing the template parameters of
    >>>template template parameters. That is sufficiently beguiling on its own
    >>>without the introduction of even more subtle semantic hair-splitting. I
    >>>argue that using /typename/ everywhere it is meaningful, and
    >>>reserving /class/ for the instances where it it necessary lends clarity
    >>>to
    >>>the code. The alternative merely saves keystrokes at the expense of
    >>>clarity.

    >>
    >>You should go argue that in comp.std.c++, please. The Standard requires
    >>'class' in some places and allows 'typename' to replace it in others. It
    >>is not done to confuse people.

    >
    >
    > The situation exists because of historical accident. The use of /class/ to
    > signify template parameters preceeded the introduction of the /typename/
    > keyword.
    >
    >
    >>If it confuses you, there are two ways to
    >>resolve that: apply some effort and learn it, or apply some effort and
    >>change it. The former happens in your head, the latter in comp.std.c++.

    >
    >
    > There is of course a third approach. That is to discuss issues of style
    > with other programmers and try to establish conventions. That, according
    > to the FAQ for this newsgroup, is properly discussed here.


    What issues of style? What conventions? 'class' is _required_ there.
    There is no convention or style about it.

    V
    Victor Bazarov, Oct 20, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TechBookReport

    Generics - good, bad or indifferent?

    TechBookReport, Oct 28, 2005, in forum: Java
    Replies:
    35
    Views:
    1,125
    TechBookReport
    Nov 1, 2005
  2. Toby A Inkster
    Replies:
    19
    Views:
    752
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,803
    Smokey Grindel
    Dec 2, 2006
  4. JT
    Replies:
    3
    Views:
    567
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Jul 1, 2007
  5. * Its my Pleasure *
    Replies:
    0
    Views:
    373
    * Its my Pleasure *
    Feb 20, 2008
Loading...

Share This Page