Re: Best practice question
Re: Best practice question
- Subject: Re: Best practice question
- From: Diederik Hoogenboom <email@hidden>
- Date: Sat, 28 Oct 2006 08:59:59 +0200
I always felt a bit awkward to reassign self so I use the following:
- (id)init
{
if (self != [super init])
return nil;
// do stuff
return self;
}
On 28-okt-2006, at 0:31, Chris Suter wrote:
We enable extra warnings (using the "-W -Wall" flags) which
generates a warning for assignments in if statements, and do it
like this:
- (id)init
{
if ((self = [super init])) {
...
}
return self;
}
- Chris
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
systems.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40obviousmatter.com
This email sent to email@hidden
_______________________________________________
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