Re: Function calling
Re: Function calling
- Subject: Re: Function calling
- From: Bob Ippolito <email@hidden>
- Date: Wed, 25 May 2005 18:50:13 -0700
On May 25, 2005, at 6:23 PM, Ondra Cada wrote:
On 26.5.2005, at 2:56, Thomas Davie wrote:
Quite agree - the part I was disputing was ``The object knows.
That's called [...] "polymorphism".''
The part was completely right. What is polymorphism?
Polymorphism in fact means that you can send the same message to
different objects, and they would behave accordingly. With strong
typing, you just limit "different objects" to subclasses of some
class, or to implementers of some protocol. (Or, in other
langauges, to other similar primitives, but I thought we are
discussing ObjC here, are we not?)
For example, in a plain function
int sum(id o) {
int sum=0;
for (NSEnumerator *en=[a objectEnumerator];o=[en nextObject];) sum
+=[o intValue];
return sum;
}
could we perhaps benefit from strong typing, having the compiler to
check that the argument is an NSArray and its items are NSNumnbers?
Nope, we could not -- actually, the very opposite: it would
*cripple* the very idea of polymorphism. The way it is written now
it would work all right with a set containing NSStrings, or, with a
few simple categories, with, say, an NSImage and its NSImageReps or
with an NSDocument and its NSWindowControllers -- or, truly, with
*whatever*.
That is polymorphism at its best: the fact we can send *any* object
messages "objectEnumerator" or "intValue" and presume it would
behave accordingly (which may also mean "reports and error": that's
definitely an appropriate reaction in case the object cannot
support the appropriate service). The strong typing just *limits*
polymorphism, never ever helps it.
With a sufficiently intelligent type system, like Haskell's, you will
have a type that describes a "list of objects that implement
intValue", which can be verified at compile time.
What you should do is take a day and read about something other than
procedural programming languages... it sounds like you've had your
head in the NSSand for the past 10 years :)
Objective-C certainly isn't the pinnacle of language design. The one
thing it does particularly well is integrate with C, everything else
in the language is pretty boring compared to what else is around.
It's certainly not the fastest, provably correct, most dynamic, etc.
It definitely is a good language for right now, but I sure hope that
it disappears in my lifetime :)
-bob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden