Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: [PATCH] Names in rulesets. (PR#559)
Home

[Freeciv-Dev] Re: [PATCH] Names in rulesets. (PR#559)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [PATCH] Names in rulesets. (PR#559)
From: Jeff Mallatt <jjm@xxxxxxxxxxxx>
Date: Tue, 12 Sep 2000 14:25:14 -0400

At 2000/09/12 14:05 , Gaute B. Strokkenes wrote:
>David Pfitzner <dwp@xxxxxxxxxxxxxx> writes:
>> gs234@xxxxxxxxx (Gaute B. Strokkenes) wrote:
>> 
>> > -  if ((!(*name)) || (0 == strcmp(name, "none")) || (0 == strcmp(name,
"no")))
>> > -    {
>> > -      return (T_LAST);
>> > -    }
>> > -  else if (0 == strcmp(name, "yes"))
>> > -    {
>> > -      return (tthis);
>> > -    }
>> > +  if (!(*name) || !strcmp(name, "none") || !strcmp(name, "no")) {
>> > +    return T_LAST;
>> > +  } else if (!strcmp(name, "yes")) {
>> > +    return tthis;
>> > +  }
>> 
>> Personally, I much prefer comparing strcmp() to zero rather than using
>> !strcmp, purely for "mnemonic" value: If strcmp EQUALS 0 then the
>> strings are EQUAL (the difference is 0), whereas if NOT strcmp, then
>> they're NOT equal - oops, not!
>
>There are so many functions that return 0 on success and true on
>failure that this has never bothered me.  I guess that the thing that
>bothered me about the above is the fact that when I see 'strcmp'
>without a leading '!', I expect it to be 'if not equal' and then I
>don't notice the trailing '==0' before it's too late.  [Side note:
>Sometimes I think that everyone should write their comparisons the
>other way round, i.e. '1 == foo' rather than 'foo == 1' to avoid
>accidental assignments.  Unfortunately, it just looks too damn odd for
>most people, myself included, to get to grips with.]  All the
>redundant parentheses really got to me too.

Those "0 == strcmp"s you removed are probably mine.  In the case of strcmp
and friends, I always write "0 == strcmp" to be as explicit and as safe
from accidental assignments as possible.  I, too, would like to see them
left in.

jjm




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