Why being an indifferent typist may be harmful

S

Steven T. Hatton

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
 
I

Ioannis Vranos

Steven said:
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.
 
S

Steven T. Hatton

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






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
 
I

Ioannis Vranos

Steven said:
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. :)
 
S

Steven T. Hatton

Ioannis said:
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
 
V

Victor Bazarov

Steven said:
[...]
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
 
I

Ioannis Vranos

Steven said:
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).
 
S

Steven T. Hatton

Victor said:
Steven said:
[...]
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
 
J

JKop

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
 
V

Victor Bazarov

Steven said:
Victor Bazarov wrote:

Steven said:
[...]
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top