Re: !foo vs foo == nil
Re: !foo vs foo == nil
- Subject: Re: !foo vs foo == nil
- From: Andy Lee <email@hidden>
- Date: Thu, 21 Aug 2008 18:38:37 -0400
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. :-)
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 (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