• 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: Best practice question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practice question


  • Subject: Re: Best practice question
  • From: j o a r <email@hidden>
  • Date: Fri, 27 Oct 2006 23:15:31 +0200


On 27 okt 2006, at 22.54, Shawn Erickson wrote:

I also personally pull the self = [super init] out of the if statement
and have the if statement check against != nil. For example...

- (id) init
{
   self = [super init];
   if (self != nil) {
       ...
   }

   return self;
}

When we're on the topic of "best practices", it could be worth noting that placing the constant value (nil in this case) to the left of the compare operator decreases the likelihood of an involuntary assignment.


Like Shawn, I also like to make the check for a nil value explicit, so in my case it looks like this:

- (id) init
{
	if (nil != (self = [super init]))
	{
		// Stuff
	}

	return self;
}

j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Best practice question
      • From: Boyd Collier <email@hidden>
    • Re: Best practice question
      • From: Chris Suter <email@hidden>
References: 
 >Best practice question (From: "Alan Smith" <email@hidden>)
 >Re: Best practice question (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: NSImages rendered at runtime and resolution independent UI...
  • Next by Date: Re: Starting a Document based application without a document
  • Previous by thread: Re: Best practice question
  • Next by thread: Re: Best practice question
  • Index(es):
    • Date
    • Thread