E
Eric Sosman
[...]
So what would you recommend in the case of inherited legacy code like
this?
typedef enum bool_n {QFALSE, QTRUE} qboolean;
...
qboolean IsFemale (edict_t *ent)
{
char *info;
if (!ent->client)
return QFALSE;
info = Info_ValueForKey (ent->client->pers.userinfo, "skin");
if (info[0] == 'f' || info[0] == 'F')
return QTRUE;
return QFALSE;
}
I'd recommend leaving it alone, unless you have some other
reason to make changes. "If it ain't broke, don't fix it." If
you decide to visit the code for some other reason -- maybe to
add a check for `info == NULL', say -- then you might consider
replacing qboolean at the same time. If you decide to ditch it,
you might do it this way
int IsFemale (const edict_t *ent) {
char *info;
if (ent->client == NULL)
return 0;
info = Info_ValueForKey (ent->client->pers.userinfo,
"skin");
return info != NULL
&& (*info == 'f' || *info == 'F');
}
Note that two of the three explicit uses of a truth constant have
vanished; this kind of simplification is often available when tests
produce manifest Boolean results. You could even get rid of the
one remaining occurrence:
int IsFemale (const edict_t *ent) {
char *info;
return ent->client != NULL
&& (info =
Info_ValueForKey (ent->client->pers.userinfo,
"skin")) != NULL
&& (*info == 'f' || *info == 'F');
}
.... but I think this breaches the bounds of good taste.