Re: Abbreviate acting strange?

From: Daniel Koepke (dkoepke@california.com)
Date: 12/07/98


The Merciless Lord of everything wrote:
>
> This was my Approach finally, except I put it in so that I could use
> it anywhere by making it a struct of it's own. for those interessted
> here it goes :

You mean "function", not "struct".  I mention this not to be
pedantic--I'm attempting a polite FYI--but just to point out that they
are two very different things and what's below is a function, just in
case you didn't know.  You may be fooled into believing it's a struct
because it's preceeded by the "struct" keyword, but that's only for
the return type ("struct char_data *").

> struct char_data *get_opponent(struct char_data * ch, char *argu)
> {
>  struct char_data *vict;
>  if (!*argu) { /* No Argument */
>   if (FIGHTING(ch)) {
>    return(FIGHTING(ch));
>   } else {
>    return NULL;
>   }
>  } else {
>   one_argument(argu, arg);
>   if (!(vict = get_char_room_vis(ch, arg))) {
>    return NULL;
>   } else {
>    return vict;
>   }
>  }
>  return NULL; // Just in case
> }

Some simplification may be in order.

  struct char_data * get_opponent(struct char_data * ch, char * argu)
  {
    if (!*argu)
      return FIGHTING(ch);

    one_argument(argu, arg);
    return get_char_room_vis(ch, arg);
  }

Sometimes I don't think to look at the code I'm writing, but a few
hours later, I'll look back and realize it's pretty damn silly to
do,

  if (MyVariable == NULL) /* i.e., !MyVariable */
    return NULL;
  else
    return MyVariable;

Since 'MyVariable' is NULL, the 'if' is unnecessary and, IMHO,
needlessly complicates the code.

-dak


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



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