Re: [dev] [sbase] style

From: <k0ga_AT_shike2.com>
Date: Wed, 19 Nov 2014 19:47:06 +0100

>> > By default I read if (!functioncall()) as 'if the function call
>> > failed'. I like the (strcmp(p, q) == 0) idiom because I don't fall
>> > into the trap of reading the statement as 'if the string comparison
>> > failed'. It is the one case I can think of where I prefer an explicit
>> > comparison to zero.
>>
>> De gustibus non est disputandum.
>>
>> However, given strcmp is such a special case, I was used to the == 0
>> idiom as well.
>> However, the more I used the ! the easier it was to read it.
>
> No. The idea is that if you are comparing pointers or functions/variables
> that obviously return 0 or 1 (like isspace() or bflag or similar) then you
> can use !v and v.
>
> If you are comparing anything else then you should explicitly check
> for it. strcmp() has 3 classes of return values < 0, == 0 and > 0.
>

Well, in this case, I usually I am only interested if the string is equal
or not, so I read !strcmp as if they are equal. I think in this case is
only personal taste, but I don't have problems with == 0 idiom.
Received on Wed Nov 19 2014 - 19:47:06 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 19 2014 - 19:48:15 CET