Re: BOOL value in Dictionary

2008-11-23 Thread Karl Goiser
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

Re: BOOL value in Dictionary

2008-11-21 Thread Clark Cox
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 c

Re: BOOL value in Dictionary

2008-11-21 Thread Gary L. Wade
Another interesting thing I've seen with some compilers is when a bit flag is defined with a signed type: short someflag : 1; a value of it being set may be -1 rather than 1, so the only way to compare it according to how you want it to work is by comparing it against 0 in some way: if (

Re: BOOL value in Dictionary

2008-11-21 Thread Ken Thomases
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 expres

Re: BOOL value in Dictionary

2008-11-21 Thread Ed Wynne
On Nov 21, 2008, at 10:54 AM, David Blanton wrote: Why is : if ( boolVar == YES) or if ( boolVar == NO) bad form? if (boolVar == YES) is bad form, but if (boolVar == NO) and if (boolVar != NO) is not. In C the concept of false has one and only one value, 0, which is #defined to be NO

Re: BOOL value in Dictionary

2008-11-21 Thread Nick Zitzmann
On Nov 21, 2008, at 8:54 AM, David Blanton wrote: Why is : if ( boolVar == YES) or if ( boolVar == NO) bad form? It's not bad form per se, but the former is unnecessarily redundant & the "== YES" can be eliminated, and the latter can be shortened using a !. Nick Zitzmann

Re: BOOL value in Dictionary

2008-11-21 Thread David Blanton
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 coc

Re: BOOL value in Dictionary

2008-11-21 Thread Michael Ash
On Fri, Nov 21, 2008 at 9:13 AM, Ken Thomases <[EMAIL PROTECTED]> wrote: > Next, even if you did want to construct an NSNumber from it, it's not a > BOOL. So +numberWithBOOL: wouldn't be appropriate. Any non-nil object > pointer would result in a true-valued NSNumber, even if [temp > objectForKey

Re: BOOL value in Dictionary

2008-11-21 Thread Heinrich Giesen
Hi, besides what Ken Thomases and Graham Cox already said, I have a remark concerning programming style: if ( colorSwitch == YES) { [colorBox setState:NSOnState]; } else { [colorBox setState:NSOffState]; } It is

Re: BOOL value in Dictionary

2008-11-21 Thread Graham Cox
On 22 Nov 2008, at 12:48 am, Richard S. French wrote: How does one get a boolean value from a dictionary object? My XML dictionary contains the value under the given key. Should this be retrieved as NSNumber or some other object? Yes, that's right. I am trying to set the state of a checkbo

Re: BOOL value in Dictionary

2008-11-21 Thread Ken Thomases
On Nov 21, 2008, at 7:48 AM, Richard S. French wrote: How does one get a boolean value from a dictionary object? My XML dictionary contains the value under the given key. Should this be retrieved as NSNumber or some other object? I am trying to set the state of a checkbox button based on the v

BOOL value in Dictionary

2008-11-21 Thread Richard S. French
How does one get a boolean value from a dictionary object? My XML dictionary contains the value under the given key. Should this be retrieved as NSNumber or some other object? I am trying to set the state of a checkbox button based on the value as below: // return syntax coloring swi