On Fri, Nov 21, 2008 at 7:54 AM, David Blanton <[EMAIL PROTECTED]> wrote:
> Why is :
>
> if ( boolVar == YES) or if ( boolVar == NO)
>
> bad form?

(boolVar == NO) is fine.
(boolVar == YES) is bad form (and could lead to incorrect results)


In C, any non-zero value evaluates to true in a boolean context, so
all of these if statements are equivalent to if(true):

if(YES)
if(42)
if(3.14159)

So it is entirely possible that you may encounter a "true" boolean
value that isn't equal to 1:

BOOL b = 42; //This is a true boolean, but it is not equal to YES

if(b == YES) //This is false
if(b) //This is true

So, the moral of the story is *never* compare a boolean value against
YES. At best it is redundant, and at worst it is incorrect.

That is, never write "if(b == YES)". Instead, it's best to write
"if(b)", "if(b != 0)" or "if(b != NO)"


-- 
Clark S. Cox III
[EMAIL PROTECTED]
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to