473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Templates and generic programming?

I have read that when you are using templates you are making generic
programs. But I don't see whats so generic about templates. You can make
generic programs without templates through the use of function overload and
the virtual functionality.

As I understand when you use templates you just increase the runtime
performance since the code is resolved at compile time. How come people are
mixing templates with generic programming when all they actually do is
increase runtime performance?
May 17 '07 #1
3 3794
On Thu, 17 May 2007 18:10:53 +0200, "Johs" <sd***@asd.comwrote:
>I have read that when you are using templates you are making generic
programs. But I don't see whats so generic about templates.
This a common misunderstanding. Alexander A. Stepanov, creator of STL,
writes: "Some of you might have also heard that generic programming is
a style of programming using C++ templates. This is not so. Generic
programming has nothing to do with C++ or templates. Generic
programming is a discipline that studies systematic organization of
abstract software components"
(http://www.stepanovpapers.com/MusserForeward.pdf).
>You can make
generic programs without templates through the use of function overload and
the virtual functionality.
As I understand when you use templates you just increase the runtime
performance since the code is resolved at compile time.
Function overloading is also resolved at compile time. Late binding
may be an advantage or a disadvantage, depending on the context.
>How come people are
mixing templates with generic programming when all they actually do is
increase runtime performance?
Better performance is always, well, better. In general I agree with
you. Templates are currently overrated in C++.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
May 17 '07 #2
Johs wrote:
As I understand when you use templates you just increase the runtime
performance since the code is resolved at compile time. How come people are
mixing templates with generic programming when all they actually do is
increase runtime performance?
Increase the runtime performance and decrease the runtime errors, given
that the issues regarding the binding are solved at compile-time.
Template and virtual are different features that provide different
functionalities. For example, how would you do a generic std::map with
virtual class? A generic MapObject* with some virtual constructor,
assignment operator and some sorting function to be possibly given as an
external parameter during the creation of the container?

It's not just a matter of performance.

Regards,

Zeppe

May 17 '07 #3
Johs wrote:
I have read that when you are using templates you are making generic
programs. But I don't see whats so generic about templates. You can make
generic programs without templates through the use of function overload
and the virtual functionality.

As I understand when you use templates you just increase the runtime
performance since the code is resolved at compile time. How come people
are mixing templates with generic programming when all they actually do is
increase runtime performance?
Using templates can also result in more static checking because types are
resolved at compile time. Parametric polymorphism is the better solution
used in most modern languages.

--
Dr Jon D Harrop, Flying Frog Consultancy
OCaml for Scientists
http://www.ffconsultancy.com/product...ntists/?usenet
May 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andre | last post by:
Hi, I've built a math library that does some matrix multiplications and other linear algebric functions. I read some place about generics or class templates and I was wondering if this will help...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
2
by: kelvSYC | last post by:
I'm trying to program something along the lines of a "trading card" idea: I have a single copy of the "card" in the program, yet there may be multiple "instances" of the "card", with differing...
2
by: Bore Biko | last post by:
Dear, I am an ordinary C programmer and I am most interesed about dynamical data structuring and programming, I don't like to use matricess and rows, I like to program with practical programs...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
7
by: Chris | last post by:
Hi All, This is a weird one but I am hoping someone can help or has some pointers, a recipe how to do the following: I have to move some code from c++ to objective-c and to do this I must...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.