On 22/08/2008, at 00.38, Andy Lee wrote:

On Aug 21, 2008, at 3:42 PM, Jim Correia wrote:
On Aug 21, 2008, at 3:54 AM, Jules Colding wrote:

For that simple reason, I'd go for nil == foo every time.

Yes, and in general you should always do "if (CONSTANT == foo)" to catch the potential "if (CONSTANT = foo)" error.

If your name is Yoda, then perhaps if (3 != x) reads naturally to you. :-)

Actually it does even though my name isn't Yoda ;-)

Anyway, it is a matter of personal taste what style you choose. I just happen to prefer to put the constant first. An old habit I guess...

Best regards,
  jules





As in most things, I think it is critical to strike a balance between code readability/skim-ability and other considerations.

I keep changing my mind about this, so my code is inconsistent about it, but I've basically come to the same conclusion. One thing I've noticed is that I rarely get a bug due to misreading a boolean expression. More often I'm looking right at it (even if it's as unmistakeable as "nil == obj") and I do the wrong thing anyway. Like I'll get the if-block and the else-block mixed up. It's like some kind of boolean-dyslexia in my brain.

I find it helps to comment my logic.

--Andy

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to