Re: Short-circuit evaluation
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