• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Obj-C] if (self) vs. if (self != nil)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Obj-C] if (self) vs. if (self != nil)


  • Subject: Re: [Obj-C] if (self) vs. if (self != nil)
  • From: Erik Stainsby <email@hidden>
  • Date: Fri, 24 Feb 2012 12:26:56 -0800

And what does the list feel about the following form (which I think I picked up from a Wil Shipley article):

    if(nil != (self = [super init]))

Myself I find it elegantly brief and imminently readable.


Time Dwarf,
Roaring Guy

On 2012-02-24, at 9:30 AM, David Duncan <email@hidden> wrote:

> On Feb 24, 2012, at 6:50 AM, Oleg Krupnov wrote:
>
>> So basically, nil is of type "void*", so the expression "self != nil"
>> compares two pointers and the result is "boolean", which is perfect
>> for testing in the "if" statement. But the "self" alone is of type
>> "pointer" and so when it is tested by the "if" statement, it's
>> implicitly cast to the type "boolean".
>
> In C any non-zero value is 'true', as such if (self) vs if (self != nil) is a pure stylistic choice, neither is more correct than the other in terms of the language itself.
> --
> David Duncan
>
>
> _______________________________________________
>
> 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

_______________________________________________

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


  • Follow-Ups:
    • Re: [Obj-C] if (self) vs. if (self != nil)
      • From: Wade Tregaskis <email@hidden>
References: 
 >[Obj-C] if (self) vs. if (self != nil) (From: Oleg Krupnov <email@hidden>)
 >Re: [Obj-C] if (self) vs. if (self != nil) (From: David Duncan <email@hidden>)

  • Prev by Date: Re: [Obj-C] if (self) vs. if (self != nil)
  • Next by Date: Re: [Obj-C] if (self) vs. if (self != nil)
  • Previous by thread: Re: [Obj-C] if (self) vs. if (self != nil)
  • Next by thread: Re: [Obj-C] if (self) vs. if (self != nil)
  • Index(es):
    • Date
    • Thread