Re: CircleMUD revisions (fwd)

From: Daniel Koepke (dkoepke@CALIFORNIA.COM)
Date: 04/25/98


Rasdan wrote:
>
> const char *GET_TITLE(ch_data * ch)
> {
>   if (!ch->player.title)
>     return ("Not yet set.");
>   else
>     return (ch->player.title);
> }

Which is only slower than:

  #define GET_TITLE(ch) ((ch)->player.title ? (ch)->player.title : \
                         "N/a");

and, actually, it's a bad idea to replace GENERIC code (which macros
typically are) with code used for a specific instance because it will
break things like "GET_TITLE(ch) = NULL;".  Of course, using
functions break things like "GET_HIT(ch) = GET_MAX_HIT(ch) / 2;",
etc. because you can't set a function equal to something.  You'd
have to do something like "SET_HIT(ch, GET_MAX_HIT(ch) / 2);" and
add the SET_HIT() function.

> More typing at first but saves you a lot of time later.

No, it breaks your code, makes things less general, and requires
you to deviate from the simple paradigm that if you can get from it,
you can set values to it.

> Then I realized I was having problems with CAN_SEE (a fact you mentioned)
> and so I rewrote the entire thing as a set of functions, which makes the
> code both easier to understand and read, but also makes the logic much
> easier to folow and safegaurd against.

That is acceptable.  Rewriting some complex macros as functions,
especially ones that are only used for _getting_ values is not that
bad of an idea in cases where you don't care about inefficiency.  On
the other hand, rewriting stuff like GET_HIT as a function is a bad
idea.

> In short, I wanted to thank you for bringing the subject up, it made me
> realize that, while a great learning tool, Macros can indeed be a
> limitation in the end (and slow you down as well, witness all the extra
> typing in the title example).

Your view is limited by your eager acceptance of a one-sided argument.
Had you thought about things more carefully, you'd see that rewriting
GET_HIT or GET_TITLE is worthless, and only serves to break code and
adding stuff like you did to your GET_TITLE() function makes the code
less general.  What about when you actually _want_ just the title,
regardless of whether it is null or not?  Oh, look...now you have to do
more typing.  You should _NEVER_ rewrite general macros/functions for
special cases, unless they are only called for those special cases (and
you are certain that they will never be used for anything but).

I urge you--for your own sake and sanity--to reconsider your position.

-dak


     +------------------------------------------------------------+
     | 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/15/00 PST