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
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 mails | Author | Date |
|---|---|---|
| Scott Andrew | Feb 10, 18:18 | |
| Scott Andrew | Feb 10, 18:35 | |
| Adhamh Findlay | Feb 10, 19:41 | |
| John Newlin | Feb 10, 20:13 | |
| Hans van der Meer | Feb 10, 20:20 | |
| Quincey Morris | Feb 10, 20:29 | |
| Jens Alfke | Feb 10, 20:45 | |
| Wade Tregaskis | Feb 10, 20:50 | |
| Ricky Sharp | Feb 10, 21:01 | |
| Jens Alfke | Feb 10, 22:44 | |
| Hans van der Meer | Feb 10, 23:26 | |
| Paul Bruneau | Feb 10, 23:29 | |
| Uli Kusterer | Feb 10, 23:40 | |
| Paul Bruneau | Feb 11, 00:18 | |
| Scott Andrew | Feb 11, 00:56 | |
| Quincey Morris | Feb 11, 02:32 | |
| mmalc crawford | Feb 11, 02:49 | |
| Jens Alfke | Feb 11, 03:05 | |
| Bill Bumgarner | Feb 11, 03:28 | |
| Quincey Morris | Feb 11, 04:35 | |
| Jean-Daniel Dupas | Feb 11, 10:27 | |
| Jens Alfke | Feb 11, 17:08 | |
| Ben Trumbull | Feb 11, 23:58 |






Cocoa mail archive

