Re: KeyValue Observing rant
Re: KeyValue Observing rant
- Subject: Re: KeyValue Observing rant
- From: Nicko van Someren <email@hidden>
- Date: Mon, 26 Apr 2004 18:36:04 +0100
On 26 Apr 2004, at 17:22, Ondra Cada wrote:
On 26.4.2004, at 17:29, mmalcolm crawford wrote:
But I'm ranting because this hidden posing or on-the-fly changing of
the isa is not documented and it limits other code (like plugins)
doing it too.
It is documented here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/Concepts/KVOImplementation.html>
Actually I *do like* the implementation -- clever!
Nevertheless, there's one detail I would somewhat agree with the
original rant: such a deep hack IMHO should be explicitly named in the
Foundation Release Notes which are part of the Panther installation. It
is not--the Release Notes on my disk just say that there's a KVO, and
that's all.
I have a different objection, one which I think is closer to objection
in the original rant.
The messing around with the isa pointer that is used to implement KVO
is just the sort of implementation specific trickery that languages
like Objective C set out to discourage. Either this sort of
interception of method access should be encapsulated into something
more formal, so that other code besides Apple's specific KVO mechanism
can make use of it, or the KVO mechanism should be incorporated into
the language itself. What they've done instead is create an external
library of objects and functions that make assumptions about the
implementation of the insides of objects. OK, so it's actually all
implemented in NSObject, and NSObject is a root class so it can do what
the hell it likes, but the whole structure of the root class is pretty
hard wired into the runtime system as far as I can tell.
I full appreciate _why_ Apple did it this way. The isa-swizzling
method allows for a fairly efficient implementation of something that
otherwise might end up either cumbersome or so (or both). On the other
hand the fact that isa-swizzling is such a powerful tool is all the
more reason why other people might want to use it. As it stands
Apple's KVO system breaks isa-swizzling for everyone else (consider the
case of you register your object for KVO, I do my own isa-swizzle and
the you de-register; something is going to break). If someone else at
Apple with access to the source of NSObject decided that they would
like to use isa-swizzling to implement, say, some cool profiler or
memory debugger, it will all get very messy.
Nicko
_______________________________________________
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.