Re: To C++ or not to C++, that is the question! Tue, Dec 09, 1997 at 10:12:08PM -0600

From: Eric Green (thrytis@IMAXX.NET)
Date: 12/09/97


On Tue, Dec 09, 1997 at 10:12:08PM -0600, Chris Jacobson wrote:
> Well, I have been sitting around thinking, now that I've implemented most
> of what I wanted to to get my MUD off the ground and out of beta phase
> (in fact when a couple more zones are ready we move into final beta
> phase), I've been debating about whether I should stay C or go C++.

> In your opinions, should I convert to C++ or no?  Will GDB demangle the
> names properly?  What are the advantages/disadvantages.

On the down side to converting to C++, the code executable size was
a little larger (probably mostly from more debugging info), and i think
the runtime size might have been slightly bigger.  We never noticed a
significant affect of this though.  Debugging is slightly harder with
gdb (getting mangled names and dealing with extra class information
over structs), but it isn't much to worry about.

On the up side to converting, C++ is perfect for programs where objects
interact with other objects, which is all a mud does.

On DG, i first modified the mud to compile with g++ or gcc, and we ran
like that for some time.  Eventually i needed to add a feature which was
much easier to do with C++, so we commited to just using g++.  New features
added after that would be done in C++ where appropriate, and old stuff
was only changed where it was a big gain using with the new stuff.

I wish i had commited to using C++ much much sooner than i did, because
it would have greately simplified the script code.  (I didn't realize at
the time how easy it was to get Circle to compile with g++.)  I used
C++ to reimplement the scripts on another mud, which cut down on the
code quite a bit because i no longer had to do three copies of a lot
of stuff for rooms, mobs, and items.

C++ for data structures were also useful.  When i had to redo the indexing
system to allow for OLC (so i didn't have any limits on the number of things
which could be added each reboot, or expensive reallocation and renumbering
of arrays), i changed the indexes to classes.  I could still access my
indexes as an array using the [] operator (saving hundreds of changes in
the code and sticking to something which looked intuitive to use), yet
didn't have an index which wasn't 32000 element array or fixed in size.
Templates are used in the DG code at least one place, which saves ugly type
casts and multiple copies of the same thing.

C++ is also good for cleaning up a few ugly bits of code.  Instead of
assembling a long string with wasteful strcats and ugly
printf(buf, "%s ...", buf, ...), a nice class was used to build long strings
without worrying where you left off.  (The sblock class in the DG code).


I would recommend first getting your mud to compile with your C++ compiler.
As you implement new things, start using C++ features, and convert old
stuff where you see a big gain.  Don't go do large changes such as change
everything to streams based, unless you have a lot of time or a real big
advantage to it.


Eric


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST