Re: self = [super init] debate.
Re: self = [super init] debate.
- Subject: Re: self = [super init] debate.
- From: Hans van der Meer <email@hidden>
- Date: Sun, 10 Feb 2008 20:20:55 +0100
On 10 feb 2008, at 19:41, Adhamh Findlay wrote:
This argument is not able what is correct, but about style. Shipley
is saying you're wasting 7 characters with the self = [super init]
assignment because [super init] does the assignment for you.
Shipley is correct that you don't need to do the assignment, but I
don't believe doing the assignment is ever going to cause problems,
its just extra.
I hesistate to enter this debate, but I think I remember a remark in
one of the Cocoa-ObjC manuals that said something like: you cannot be
sure that the call to super returns the same object than the one that
is calling. In that case it is more than style what counts here.
Suppose [super init] returns another object (possibly in a more
specialized class and possibly for reasons of efficiency and/or
performance) by allocating and initializing it. In this case self
should reflect that by being assigned that object. Thus
[super init];
if(self != nil)
then will be the original uninitialized, not the initialized object.
Whereas the following construct does incorporate the change:
self = [super init];
if(self != nil) ...
return self;
The point is, the caller of [super init] cannot know (without doing
some introspection) what is returned. And therefore should take the
surest path.
Please correct me if I am seeing this wrong.
Hans van der Meer
_______________________________________________
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