James Carlson wrote:
> Garrett D'Amore writes:
>   
>> I'm not sure if the Style Guide makes that difference.  I don't know.  
>> Frankly, this is one of my least favorite rules in the guide, because I 
>> happen to think "if (!foo)" is clearer than "if (foo != 0)".  But I 
>> didn't write the guide, or get to vote on it -- but I do assume that I'm 
>> bound to follow it.
>>
>> If I've misinterpreted what it says, I'd be happy to be corrected, 
>> because to *my* eyes, I agree with Peter.
>>     
>
> I think there's general agreement that treating a bitwise flag test as
> a boolean results in nicely readable code, and should be encouraged.
> In fact, I'd go so far as to say that comparing those expressions
> against zero needs to be outlawed.  "== 0" is very hard to read as
> "not set," while "!= 0" has a hint of not-i-ness about it.
>   

Hmm... okay, well, so who decides this?  I actually try to adhere to the 
rules, even the ones I disagree with, and if the rules are changing (or 
I've misunderstood them), then I guess I should go back and change the code.

And, if this is going to be a new rule (or perhaps a clarification), how 
do we go about getting the style guide updated?

JBeck (C-Team lead)?

    -- Garrett
> (Whether we ought to have bitwise values at all or should be using
> explicit booleans is probably a separate matter, and doesn't matter
> much given the context here.)
>
> What the Style Guide is trying to prevent is the use of weird
> non-boolean values as though they were boolean.  This is fairly ugly,
> because it just doesn't read right out loud:
>
>       if (foo = malloc(10)) {
>               /* looks like I can allocate 10 more bytes! */
>       }
>
> If foo is ... what?  This is much worse:
>
>       if (open("/dev/null", O_RDWR)) {
>               /* now why is stdin already open? */
>       }
>
> The code needs to be readable.
>
>   

_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to