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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to