[Top][All Lists]
[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/
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), (continued)
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Pascal J . Bourguignon, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Nicola Pero, 2004/02/07
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Pascal J . Bourguignon, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Richard Frith-Macdonald, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Pascal J . Bourguignon, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/09
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?),
Pascal J . Bourguignon <=
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), David Ayers, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Alexander Malmberg, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Nicola Pero, 2004/02/10
- Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Kazunobu Kuriyama, 2004/02/08
Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?), Alexander Malmberg, 2004/02/10