Skip navigation.
 
mlRe: self = [super init] debate.
FROM : Hans van der Meer
DATE : Sun Feb 10 20:20:55 2008

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

Related mailsAuthorDate
mlself = [super init] debate. Scott Andrew Feb 10, 18:18
mlRe: self = [super init] debate. Scott Andrew Feb 10, 18:35
mlRe: self = [super init] debate. Adhamh Findlay Feb 10, 19:41
mlRe: self = [super init] debate. John Newlin Feb 10, 20:13
mlRe: self = [super init] debate. Hans van der Meer Feb 10, 20:20
mlRe: self = [super init] debate. Quincey Morris Feb 10, 20:29
mlRe: self = [super init] debate. Jens Alfke Feb 10, 20:45
mlRe: self = [super init] debate. Wade Tregaskis Feb 10, 20:50
mlRe: self = [super init] debate. Ricky Sharp Feb 10, 21:01
mlRe: self = [super init] debate. Jens Alfke Feb 10, 22:44
mlRe: self = [super init] debate. Hans van der Meer Feb 10, 23:26
mlRe: self = [super init] debate. Paul Bruneau Feb 10, 23:29
mlRe: self = [super init] debate. Uli Kusterer Feb 10, 23:40
mlRe: self = [super init] debate. Paul Bruneau Feb 11, 00:18
mlRe: self = [super init] debate. - Thanks Scott Andrew Feb 11, 00:56
mlRe: self = [super init] debate. Quincey Morris Feb 11, 02:32
mlRe: self = [super init] debate. mmalc crawford Feb 11, 02:49
mlRe: self = [super init] debate. Jens Alfke Feb 11, 03:05
mlRe: self = [super init] debate. Bill Bumgarner Feb 11, 03:28
mlRe: self = [super init] debate. Quincey Morris Feb 11, 04:35
mlRe: self = [super init] debate. Jean-Daniel Dupas Feb 11, 10:27
mlRe: self = [super init] debate. Jens Alfke Feb 11, 17:08
mlre: self = [super init] debate. Ben Trumbull Feb 11, 23:58