Re: BOOL value in Dictionary
Re: BOOL value in Dictionary
- Subject: Re: BOOL value in Dictionary
- From: Karl Goiser <email@hidden>
- Date: Mon, 24 Nov 2008 16:20:10 +1100
The issue is that a boolean value is not numeric, but the denotation
of truth or falsehood. If you take boolVar to represent the
proposition that "Socrates is a man", then saying:
if (boolVar == YES)
is equivalent to:
if ("Socrates is a man" == YES)
This is obviously a correct expression - it's just that the "== YES"
part is redundant.
Again, when asking if a package is at the airport, you don't say, "Is
it the case that the package is at the airport is true?", you say, "is
the package at the airport".
The problem is that the designers of C (and other languages as well)
decided to treat falsehood as zero and truth as non-zero, and
implement them using integer types. The trick is that, implemented
this way, boolean operators can use arithmetic ones: 'or' as addition
and 'and' as multiplication. For example, false or false is false (0
+ 0 = 0).
This leads to the stripping of information: truth or falsehood gets
reduced to numeric values and the logic of what you are coding
changes. I have seen examples of C code where logical values are
compared to zero (and used in expressions with + etc operators). From
the above, this would be like asking:
if ("Socrates is a man" != 0)
which is absurd.
To this end, I always
#import <iso646.h>
and use 'and' and 'or' as much as I can in my logical expressions...
Regards,
Karl
On 22/11/2008, at 2:54 AM, David Blanton wrote:
Why is :
if ( boolVar == YES) or if ( boolVar == NO)
bad form?
David Blanton
David Blanton
_______________________________________________
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
_______________________________________________
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