• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: setState has no effect on an NSButton
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setState has no effect on an NSButton


  • Subject: Re: setState has no effect on an NSButton
  • From: David Duncan <email@hidden>
  • Date: Tue, 10 May 2011 09:16:09 -0700

On May 9, 2011, at 9:55 PM, Graham Cox wrote:

> Why bother? Because it's more readable than all those if/else constructions, and hence, less prone to bugs. Also, if( st == YES)...else if(st == NO) is redundant - a BOOL can only be YES or NO. The optimiser might optimise away the second comparison anyway, but why be windy in the first place?


A BOOL is just a typedef of an unsigned char, so technically it can hold any value from 0-255. It usually only holds 0 (NO) or 1 (YES) but this is not required and there is code out there that will happily return 2-255 expecting that you treat the value the same as YES.

Basically, YES is only useful as an assigned value, not as a comparison value. Code that compares against YES is typically not defensive enough in the face of other semi-badly behaved code. From a performance point of view, the compiler actually cannot optimize away the comparison to NO after the comparison to YES, because it cannot guarantee that the value you are comparing against isn't a value other than YES or NO in most cases.
--
David Duncan

_______________________________________________

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

References: 
 >setState has no effect on an NSButton (From: Martin Batholdy <email@hidden>)
 >Re: setState has no effect on an NSButton (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Why NSClassFromString(@"CADisplayLink")?
  • Next by Date: Call NSView's -drawRect method manually
  • Previous by thread: Re: setState has no effect on an NSButton
  • Next by thread: Why NSClassFromString(@"CADisplayLink")?
  • Index(es):
    • Date
    • Thread