Re: BOOL value in Dictionary
Re: BOOL value in Dictionary
- Subject: Re: BOOL value in Dictionary
- From: Ken Thomases <email@hidden>
- Date: Fri, 21 Nov 2008 10:25:24 -0600
On Nov 21, 2008, at 9:54 AM, David Blanton wrote:
Why is :
if ( boolVar == YES) or if ( boolVar == NO)
bad form?
Let me ask you this: why wouldn't you use:
if ( (boolVar == YES) == YES )
or
if ( ( (boolVar == YES) == YES ) == YES )
?
boolVar is already a boolean expression. Comparing it to YES forms
another boolean expression, but it's redundant and more complex than
necessary.
In addition, although a BOOL variable arguably _should_ only contain
YES or NO (or TRUE or FALSE), it might contain other values. Any non-
zero value should be interpreted as YES because that's the convention
for booleans in C, but it may not necessarily equal YES.
Consider:
if ((boolVar == YES) || (boolVar == NO))
doSomething();
else
{
// We _should_ never get here, but we might!
breakHorribly();
}
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden