Re: !foo vs foo == nil
Re: !foo vs foo == nil
- Subject: Re: !foo vs foo == nil
- From: Jim Correia <email@hidden>
- Date: Thu, 21 Aug 2008 15:42:35 -0400
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.
The previously mentioned warning will catch an unintentional
assignment as long as you don't overzealously use extra sets of
parenthesis.
And to use Uli's example, the compiler will happily accept
x =+ 5;
even when that isn't what you intended. At the end of the day, you are
responsible for what you typed, typos included.
Jim
_______________________________________________
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