471,074 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,074 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 2749
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andre | last post: by
22 posts views Thread by E. Robert Tisdale | last post: by
2 posts views Thread by kelvSYC | last post: by
2 posts views Thread by Bore Biko | last post: by
25 posts views Thread by Ted | last post: by
104 posts views Thread by JohnQ | last post: by
7 posts views Thread by Chris | last post: by

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.