• 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: Wed, 24 Jun 2009 00:47:08 +1000


On 24/06/2009, at 12:24 AM, Michael Ash wrote:

If both expressions must be evaluated, then store them into separate
variables before combining them. Or better yet, if possible, redesign
your code so that it does not require side effects of boolean
expressions to happen in the first place.


I'd like to if I could - unfortunately in this case the method in question is -validateMenuItem: which is designed to have intentional side-effects, like setting the item's state or title, as well as returning a boolean value for the enable state. The API might have been better if it returned nothing and made you handle the enable state directly also, but it wasn't so I'm stuck with it.

The reason that I ever have to OR together two of these is because I'm using quite a lot of message forwarding in my app, so in 1 or 2 places I have to OR my forwarded -validateMenuItem: with super's implementation. I have managed to eliminate nearly all the places where I was doing this but not all - but it's getting cleaner all the time so maybe we'll end up without the need for this at some point.

--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: Kyle Sluder <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>)
 >Re: Short-circuit evaluation (From: Graham Cox <email@hidden>)
 >Re: Short-circuit evaluation (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: What is the best way to store some kind of identifying string in an interface builder object?
  • Next by Date: Re: Amount of Arguments per Method
  • Previous by thread: Re: Short-circuit evaluation
  • Next by thread: Re: Short-circuit evaluation
  • Index(es):
    • Date
    • Thread