[Freeciv-Dev] Re: [PATCH] Names in rulesets. (PR#559)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Jeff Mallatt <jjm@xxxxxxxxxxxx> writes:
> 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.
Hm. When I wrote this, I thought that the code in question used
strcmp() == 0 (which I have seen a lot elsewhere in Freeciv, and I
don't like.) Obviously, it doesn't. Sorry.
--
Big Gaute (not to be confused with LG)
.. I want a COLOR T.V. and a VIBRATING BED!!!
[Freeciv-Dev] Re: [PATCH] Names in rulesets. (PR#559), Gaute B. Strokkenes, 2000/09/12
[Freeciv-Dev] Re: [PATCH] Names in rulesets. (PR#559), Gaute B. Strokkenes, 2000/09/14
|
|