• 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: Short-circuit evaluation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Short-circuit evaluation


  • Subject: Re: Short-circuit evaluation
  • From: Graham Cox <email@hidden>
  • Date: Tue, 23 Jun 2009 22:16:46 +1000


On 23/06/2009, at 10:03 PM, Igor Mozolevsky wrote:

BOOL someValue = [object returnsBool] | [anotherObject alsoReturnsBool];

which is a bitwise OR of two YESes, essentially.


OK, makes sense... and since ||= is not valid, there should be no hidden gotcha with organising things this way.

I was running into a problem with short-circuit evaluation with BOOL foo = [a bar] || [b baz]; where baz wasn't being called. Splitting the code down to

BOOL foo = [a bar] | [b baz]; will always call baz but the result <foo> will be identical...

The problem crops up in combining calls to -validateMenuItem:, where the validation not only returns YES or NO but may also have side effects like changing the state of item. The call must be made even if the actual result is logically redundant.

--Graham
_______________________________________________

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


  • Follow-Ups:
    • Re: Short-circuit evaluation
      • From: Michael Ash <email@hidden>
References: 
 >Short-circuit evaluation (From: Graham Cox <email@hidden>)
 >Re: Short-circuit evaluation (From: Igor Mozolevsky <email@hidden>)
 >Re: Short-circuit evaluation (From: Igor Mozolevsky <email@hidden>)

  • Prev by Date: Re: Short-circuit evaluation
  • Next by Date: Re: Problem with NSValueTransformer, NSTableView and NSAttributedString
  • Previous by thread: Re: Short-circuit evaluation
  • Next by thread: Re: Short-circuit evaluation
  • Index(es):
    • Date
    • Thread