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: rf13@xxxxxxxxxxxxxxxxxxxxxx, Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>, Petr Baudis <pasky@xxxxxxxxxxx>
Cc: Reinier Post <rp@xxxxxxxxxx>, Freeciv developers <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: curiosity
From: Andrew Sutton <ansutton@xxxxxxx>
Date: Sun, 2 Dec 2001 11:46:58 -0500

On Sunday 02 December 2001 03:37 am, Raimar Falke wrote:
> On Sun, Dec 02, 2001 at 09:07:49AM +0100, Petr Baudis wrote:
> > > > Well not solid, but: I dislike C++. I don't want to start a holy war
> > > > on this. It just means that you have to define such fundamental
> > > > decision very early.
> >
> > I agree. I dislike C++ too.
> >
> > > point  taken ;) for some reason alot of people don't like c++ - or OO
> > > at all for that matter. i was that way for a while too, until i was
> > > forced to do c++ dev at work. now i love it. it's just a great,
> > > powerful language - and it's easy to design for :)
> >
> > Well, I just don't see any huge benefit in it.
> >
> > Why C++ objects?
>
> I think it is just very very tempting to convert the structs into real
> objects. IMHO the objectciv project also didn't go further than this
> before it went dead.
>
> > What's wrong on C objects? Inheritance? You can do it in C
> > too. Templates are bloating and discouraged anyway. So only benefit
> > is even more bloated and unreadable and messy code, we don't have
> > enough of it already?
>
> Ask Andrew.

oh, thanks raimar, just pass all questions this way ;)

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.

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.

andy


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