Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] Re: curiosity
Home

[Freeciv-Dev] Re: curiosity

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv Developers <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: curiosity
From: Justin Moore <justin@xxxxxxxxxxx>
Date: Sun, 2 Dec 2001 12:42:12 -0500 (EST)

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



[Prev in Thread] Current Thread [Next in Thread]