[Freeciv-Dev] Re: curiosity
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Sun, 2 Dec 2001, Raimar Falke wrote:
> On Sun, Dec 02, 2001 at 11:46:58AM -0500, Andrew Sutton wrote:
> > templates can be ugly if they aren't treated carefully. it can make code
> > look
> > worse too. for example the declarations of an iterator for a map:
> >
> > std::map< unsigned, FC_Unit * >::iterator i;
> >
> > however, this can be significantly simplified using a typedef.
> >
> > typedef std::map< unsigned, FC_Unit * > Unit_Map;
> > Unit_Map::iterator i;
> >
> > it's readable, it looks nice, it works nice.
Until you get it into a debugger. Have you ever tried to follow the
STL around in gdb? That *alone* should be a reason NOT to use the STL
(not necessarily C++, just the STL).
> > as for code bloat with templates, that's true... sort of. it's a tradeoff. a
> > template class adds absolutely NO overhead when it's defined. however, when
> > it's instantiated, it defines and instantiates a new class - thereby adding
> > to the size of the code. however, the alternative would be to define a new
> > class for every template that is instantiated. consider a list class (not
> > STL). there's 2 ways of defining lists.
> > 1. templates
> > 2. inheritance
> >
> > with templates, you just instantiate the class and a new instance of the
> > class is created.
> > list< int > a;
> >
> > with inheritance, you define a base list class and derive instances of it.
> >
> > class list {};
> > class int_list : public list {};
> >
> > see? tradeoff. either way, you end up with more code. both solutions provide
> > typesafe containers. however, the inheritance implementation means actually
> > writing those classes and increases the possiblity of errors in the code.
>
> And now compare this to common/speclist and common/genlist. These
> provide typesafe access without extra bloat.
Agreed. When used properly and in a controlled environment, void* can
be used effectively as an abstraction mechanism without a lot of the nasty
C++ overhead.
-jdm
Department of Computer Science, Duke University, Durham, NC 27708-0129
Email: justin@xxxxxxxxxxx
- [Freeciv-Dev] Re: curiosity, (continued)
- [Freeciv-Dev] Re: curiosity, Raimar Falke, 2001/12/01
- [Freeciv-Dev] Re: curiosity, Andrew Sutton, 2001/12/01
- [Freeciv-Dev] Re: curiosity, Petr Baudis, 2001/12/02
- [Freeciv-Dev] Re: curiosity, Raimar Falke, 2001/12/02
- [Freeciv-Dev] Re: curiosity, Andrew Sutton, 2001/12/02
- [Freeciv-Dev] Re: curiosity, Raimar Falke, 2001/12/02
- [Freeciv-Dev] Re: curiosity, Andrew Sutton, 2001/12/02
- [Freeciv-Dev] Re: curiosity,
Justin Moore <=
- [Freeciv-Dev] Re: curiosity, Andrew Sutton, 2001/12/02
- [Freeciv-Dev] Re: curiosity, Reinier Post, 2001/12/02
- [Freeciv-Dev] Re: curiosity, Andrew Sutton, 2001/12/02
[Freeciv-Dev] Re: curiosity, Reinier Post, 2001/12/02
[Freeciv-Dev] Re: curiosity, Raimar Falke, 2001/12/01
|
|