Re: isa
Re: isa
- Subject: Re: isa
- From: Jeff LaMarche <email@hidden>
- Date: Sun, 2 Jun 2002 21:52:01 -0700
On Sunday, June 2, 2002, at 08:48 PM, Aram Greenman wrote:
>
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."
No, they wouldn't. Although Java is strongly typed, it is still a fairly dynamic
language, and this is something that is done in a lot of places - for example
in java.util.Vector and java.util.HashMap. You declare the equivalent of NSObject,
which is simply Object. Although subclassing from Object in Java is not as
commonly done as subclassing from NSObject in Cocoa, it is still good form,
and my experience is that when you take an Object as an argument, it will
even accept Java objects that were not subclassed from Object (although it
doesn't seem like it should).
>
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.
I have to disagree here. Many people have acknowledge that you are free to
do it, but there has yet to be an example of a compelling reason to do it.
If you can show a real-code situation where this problem occurs and can explain
why it is unavoidable, then your argument is better, but "normal" is not really
the right word here. There are several people with many, many years combined
experience (and I'm excluding myself in that =) ) telling you you've proposed
a solution in search of a problem. You might understand and know isa's behavior,
but you don't control it, and don't know what will happen to it in future
versions of the runtime.
Everybody acknowledges that there are times when you need to break the rules,
but the solution you've proposed is really very similar to hand-coding assembly
language. There are rare times in very performance-sensitive situations where
this is appropriate, but it would typically be done as a last resort - many
of the early games will no longer run on current processors because the chip
instruction set has changed. In your solution, one change to the runtime could
destroy your program. Do it if it's absolutely necessary, but don't use a
novel solution with serious potential drawbacks unless you have to.
>
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.
I think you just said the same thing I did in an earlier paragraph - you proposed
a solution looking for a problem. =)
Jeff
_______________________________________________
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: Andy <email@hidden>
- Re: isa
- From: Phillip Morelock <email@hidden>
References: | |
| >Re: isa (From: Aram Greenman <email@hidden>) |