gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?)


From: Pascal J . Bourguignon
Subject: Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?)
Date: Tue, 10 Feb 2004 03:57:46 +0100

Kazunobu Kuriyama writes:
> So I'm wondering if changing the expression to
>    [NSNumber numberWithBool: isYES(i=256)];
> or something like this always gives the right answer.  Sometimes it is, but
> what if generating NO is the coder's genuine intention?

Then it was  obscure code. He should have  made his intention explicit
and he shoudl have written:

    [NSNumber numberWithBool: (((i=256)&0xff)!=0)]

confident that the compiler would have generated EXACTLY the same code
(at least with -O3).


> If we have to pay attention to semantics defined by ourselves as well as
> syntax, I'm afraid it makes the maintenance of code harder because we have
> to take two possible interpretations into consideration and decide which is
> the coder's intention.  Furthermore, it unexpectedly reduces the readability
> of code when semantics and syntax respectively give contradictory
> interpretations.

In any case, 

     [NSNumber numberWithBool: i=256]

is much less readable than:

     [NSNumber numberWithBool: (((i=256)&0xff)!=0)]

which itself is much less readable than:

     i=256;
     [NSNumber numberWithBool: NO]

(Here  you  see  another  "stylistic"  rule  in  my  book:  never  use
assignation in expressions, only in statements, and one at a time);



-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/




reply via email to

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