Re: Method not seeing array as array
Re: Method not seeing array as array
- Subject: Re: Method not seeing array as array
- From: Shawn Erickson <email@hidden>
- Date: Wed, 2 Feb 2005 17:43:30 -0800
On Feb 2, 2005, at 5:24 PM, Andrew Farmer wrote:
On 2 Feb 2005, at 13:08, Marco Scheurer wrote:
While not harmful, and probably good style (except for the the
'if(!self) return nil' line)
Is there something wrong with
if(!self) return nil;
other than its being a shorthand for
if(self == nil) return nil;
?
In reality no... it more clearly conveys your intent to test against
nil since nil explicitly implies no object.
(following written in mail rapidly...)
I personally prefer the following pattern for simple cases...
-(id)init
{
if ((self = [super init]) != nil) {
...blah...
}
return self;
}
...or the following for more complex cases (assumes dealloc will clean
stuff as needed)...
-(id)init
{
bool failed = NO;
if ((self = [super init]) == nil) {
return nil;
}
for(;;) {
..blah..
if (someThingFailed) {
failed = YES;
break;
}
..blah..
if (someThingElseFailed) {
failed = YES;
break;
}
}
if (failed) {
[self release];
self = nil;
}
return self;
}
...or for those that don't fear the goto...
-(id)init
{
if ((self = [super init]) == nil) {
return nil;
}
..blah..
if (someThingFailed) goto initFailed;
..blah..
if (someThingElseFailed) goto initFailed;
return self;
initFailed:
[self release];
return nil;
}
-Shawn
_______________________________________________
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