[LC++]Generic programming vs OO inheritance
9odb6x3rfr001 at sneakemail.com
Wed Aug 22 08:11:05 UTC 2001
Kai Vehmanen kai.vehmanen at wakkanet.fi [mltuxcpp/linux-cpp list] wrote:
> On Thu, 16 Aug 2001, Mark Phillips wrote:
> The same thing happens in C++, but in Eiffel the required interface is
> explicitly stated. And this is a very nice feature. For instance all
> algorithms working on collections can be templatized with T->COLLECTION,
Take a look at Boost (www.boost.org) for some well thought out idioms using
C++ templates to good effect. Constraining a template to cause an error
unless an argument is derived from a given base class needs no language
support (syntactic sugar), just a library of appropriately defined
templates; the real problem are poor error messages, at the moment, i.e.
error messages which do not tell you "T is not derived from Base" but
some convoluted equivalent.
> My biggest grief with gcc C++ templates is the lack of support for export.
> As it is now, I have to include the routine implementations from header
> files. In a big project, with widely used template classes, this means
> that a small change to the implementation of some template class routine
> implementation results in recompilation of practically the whole system.
In my opinion, you cannot have both compile time optimization, which
is what templates are all about really, and modular compilation. The
appropriate approach, I gather, goes along the lines of:
- do not improvise "heavy" templates, those requiring head-spinning
tricks ... use *only* libraries when doing applications, writing at
best simple templates and taking the time to design them right so
you don't have to change them over and over again;
- if you need "heavy" templates, change hats ... take up the mindset of
the library writer (hire one, look for an Open Source library, you
have many options) and be prepared to spend much more time designing
and testing the templates than actually coding them.
Besides, templates by definition require that the source be available
which in the context of Open Source software is a good thing.
Linux - the choice of a GNU generation.
More information about the tuxCPProgramming