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 (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/lists%40goiser.com

This email sent to [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