Re: self = [super init], nil?
Re: self = [super init], nil?
- Subject: Re: self = [super init], nil?
- From: Thomas Davie <email@hidden>
- Date: Mon, 10 May 2010 19:19:30 +0100
On 10 May 2010, at 16:49, Thomas Wetmore wrote:
> This is the initializer pattern I settled on a few years back:
>
> - (id) init...
> {
> if (!(self = [super init])) return nil;
> ...
> return self;
> }
>
> Trillions of calls later I can report upon its serviceability.
>
> I come from an old school, formed in the mid 60's, the Savers Institute for Indentation Levels and Code, when Fortran on punch cards was de rigueur. My graduate work was done at the Bell Labs Institute of Advanced Obfuscation when C was cool. Both schools have since lost their raison d'être, and are sometimes ridiculed, but old alumni still cherish their dogmas.
Just to add to the heap of style opinions...
I personally really dislike this one, for two reasons:
1) I hate that in C a statement can be an expression, it's not immediately clear when and how it'll be executed, and it's not immediately clear that your if statement might have a side effect. Keeping if statements free of side effects is good.
2) While using a pointer in a comparison is not a type error in C, it certainly is in my brain – pointers and booleans are not the same thing.
Because of those two reasons I use:
- (id)init
{
self = [super init];
if (nil != self)
{
...
}
return self;
}
Bob_______________________________________________
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