gnustep-dev
[Top][All Lists]
Advanced

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

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


From: Helge Hess
Subject: Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?)
Date: Mon, 2 Feb 2004 02:31:48 +0100

On 30.01.2004, at 18:11, Nicola Pero wrote:
I think a BOOL variable should take the values 0 for NO and 1 for YES.

Coding standards should recommend that all code writing or returning a
BOOL always uses 0 for NO and 1 for YES, as everyone knows and agrees on
those values and their meanings.

OK, this time I checked ;-)
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ 5objc_language_summary/chapter_10_section_3.html#//apple_ref/doc/uid/ 20001428/TPXREF102

Why do you think that YES evaluates to "1"? This is a completely arbitary choice, YES could as well be defined like -1 or 5 or 100.

I do not agree that YES always implies "1". And code which assumes this, is even more broken than the one which at least compares against the symbol YES.

I don't have particular objections to change 'if ([this canDoThat] ==
YES)' into 'if ([this canDoThat])', if we write clearly in the coding
standards that this can be done only for methods returning a BOOL, and
that everything else (pointers, integers, etc) must be compared against
something. So whenever you'd see 'if ([this doThat])' you know that the
result type must have been a BOOL since it's compared to nothing.

This sounds reasonable for me. While I still prefer "if(ptr)" quite a useful and not to weird shortcut.

Greets
  Helge
--
http://docs.opengroupware.org/Members/helge
OpenGroupware.org





reply via email to

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