Re: isa
Re: isa
- Subject: Re: isa
- From: Aram Greenman <email@hidden>
- Date: Sun, 2 Jun 2002 19:23:20 -0700
On Sunday, June 2, 2002, at 01:23 AM, Marcel Weiher wrote:
On Saturday, June 1, 2002, at 11:22 Uhr, Aram Greenman wrote:
The thread where this originally came up (re. ObjC inits vs. C++
constructors) had to do with sending messages to self in an
initalizer, which is _usually_ a bad idea,
No. In Objective-C it is not "usually" considered a bad idea at all.
since it is possible the method called might access unitialized
instance variables, depending on where you are in the initializer
chain.
Well, don't call methods that might access uninitialized instance
variables, then!
Yes, of course, but what if (probably the third time this has been
brought up between this thread and the previous one) class A sends [self
foo] in -init or whatever its designated initializer is. -[A foo]
doesn't access any uninitialized instance variables. A is later
subclassed by A', which overrides -foo with an implementation which
accesses instance variables declared in A' (and therefore will _always_
be uninitialized when -[A init] is called by -[A' init]). Now the
seemingly safe message [self foo] in -[A init] could potentially cause
unexpected behavior.
I admit that this is _not_ that big of a deal, and is avoidable by
common sense and documentation, however, IMHO it is better to provide
for the possibility that someone (possibly yourself) might subclass your
class without looking at the code in question or reading your comments.
Aram
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
- Follow-Ups:
- Re: isa
- From: Ondra Cada <email@hidden>
- Re: isa
- From: Phillip Morelock <email@hidden>
References: | |
| >Re: isa (From: Marcel Weiher <email@hidden>) |