Re: isa
Re: isa
- Subject: Re: isa
- From: Phillip Morelock <email@hidden>
- Date: Sun, 02 Jun 2002 21:19:24 -0700
On 6/2/02 8:48 PM, "Aram Greenman" <email@hidden> wrote:
>
On Sunday, June 2, 2002, at 01:16 AM, Marcel Weiher wrote:
>
>
>>>> I also suggested changing the object's isa temporarily, with the
>
>>>> disclaimer that it might be a bad idea.
>
>>>
>
>>> It is a very bad idea, especially the temporary swizzling.
>
>>
>
>> Exactly how? That is my suspicion, but I would like to know
>
>> specifically why it is a bad idea.
>
>
>
> Unintended and unforseen side-effects.
>
>
There are no unforeseen side-effects. There are only defined and
>
undefined behaviors.
>
>
> The point is that the problems are difficult to forsee precisely,
>
> because the assumption that the isa pointer is correct is a very basic
>
> assumption that is made throughout the system.
>
>
However, if A' inherits from A, saying an A' is an instance of A _is_
>
correct, insofar as it has all the instance variables of A and therefore
>
possesses everything that makes an A an A.
>
>
>
> The other, maybe bigger, problem is that if you even *want* to do this,
>
> you are ignoring a message that your code is trying to tell you very
>
> loudly: I am organized incorrectly!
>
>
Suppose you asked a Java programmer, "I want to declare a variable that
>
can hold any kind of object. How can I do that?", they would probably
>
say "That is completely unnecessary. Your code is organized incorrectly."
>
>
If you were strictly limited to a Java way of thinking, that would be
>
correct. With all due respect, it seems that your response here is
>
limited to an 'normal' Obj-C way of thinking.
>
Huh? As a programmer often "limited to a Java way of thinking" I must tell
you that you are mistaken IMHO. How do you think generic data structures
are constructed in Java? They take and return objects of type Object (or
that implement an interface like Comparable) even though in reality nobody
is storing raw Object instances in data structures.
It's called polymorphism.
fillup "the java guy trying to learn Obj-C" morelock
>
When I first started learning Obj-C, it didn't seem that dynamic typing
>
was really that useful. Of course I quickly saw that I was wrong. I
>
admit that this isa-manipulation doesn't _seem_ that useful and of
>
course it isn't strictly necessary. But if it was possible to for an
>
object to invoke multiple behaviors for the 'same' message, it might
>
find uses that aren't readily apparent. My intent here was not to try to
>
get around good programming practice or the correct Obj-C way of doing
>
things, but to see if something was possible, and _then_ see how it
>
could be used.
>
>
Maybe this is a language-level feature and can't be (easily) implemented
>
in Obj-C. As I said at the beginning of this thread, that is my
>
suspicion, but I disagree with your statement that:
>
>
> The point is that the problems are difficult to forsee precisely
>
>
I don't see how this can be true. A quick grep of the source to the
>
runtime shows isa to appear in only 64 lines. I haven't looked at a lot
>
of it yet, but since it is known exactly how the isa pointer is used by
>
the runtime, any use that would be undesirably affected by the
>
manipulation should be identifiable (for example, maybe the runtime also
>
writes to the isa pointer after it is initialized, or something).
>
>
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.
_______________________________________________
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.
References: | |
| >Re: isa (From: Aram Greenman <email@hidden>) |