Re: !foo vs foo == nil
Re: !foo vs foo == nil
- Subject: Re: !foo vs foo == nil
- From: Jules Colding <email@hidden>
- Date: Thu, 21 Aug 2008 09:06:05 +0200
On 21/08/2008, at 01.56, John C. Randolph wrote:
On Aug 20, 2008, at 4:15 PM, Torsten Curdt wrote:
There was a common perception that NULL is not really the same as
nil. But seems like in the end it really is (void*)0.
They differ in type, not in value.
"NULL" is (void *) 0.
"nil" is (id) 0.
"Nil" is (Class) 0.
Personally, I prefer "if (!foo)" over "if (foo == nil)", because the
latter has the hazard of a typo that compiles. You can lose a fair
bit of time staring at "if (foo = nil)" before you spot the mistake.
Which is why you should always write "if (nil == foo)".
--
jules
_______________________________________________
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