home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.object
- Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!netcom.com!objsys
- From: Bob Hathaway <objsys@netcom.com>
- Subject: Re: FAQ Part 1 (of 2) [ polymorphism or latent typing? ]
- Message-ID: <1993Jan22.004420.16674@netcom.com>
- Sender: objsys@netcom.com (Object Systems)
- Organization: Object Systems
- References: <1993Jan13.061114.18430@netcom.com> <PCG.93Jan20002119@decb.aber.ac.uk>
- Date: Fri, 22 Jan 1993 00:44:20 GMT
- Lines: 196
-
- In article <PCG.93Jan20002119@decb.aber.ac.uk>, pcg@aber.ac.uk (Piercarlo Grandi) writes:
- >The discussion on polymorphism is in another article, but let me
- >register here my deep dissent over the idea that variables (or even
- >worse, objects, except wheere they can change class over time) can be
- >polymorphic; procedure implementations only can be polymoprphic
- >(procedure interfaces too if one accepts the misleading but popular term
- >"ad hoc polymorphism").
-
- This is only with your procedural view of object-orientation. Polymorphic
- objects are the rule in an object-oriented [read "strong equivalence"] view,
- which I believe is preferred as pointed out in my previous posting. Also,
- [I have done work in this area], the cases of objects becoming and assuming
- (through something like pointer semantics) other objects can be unified, as
- I have done in my definition of polymorphism. In use there is a difference
- (assigning or becoming), but not in definition. Also, I show below that the
- canonical use of the term "polymorphism" refers to objects that can assume
- (be assigned to) many objects and does *not* usually refer to objects that
- can become (or change themselves into) other objects. This is more of
- an interesting special case, usually referred to as metamorphosis and not
- polymorphism, as I recall.
-
- >I think that by polymorphic variables you mean variables that are not
- >restricted at compile time to denote values of one class only, as in
- >the various cases (bounded, unbounded) of latent "typing".
-
- But this is polymorphism in programming, since it is objects assuming or
- becoming many different objects, or the essence of polymorphism. If achieved
- thru latent typing, fine. Since Strachey defined parametrically polymorphic
- functions (functions parameterized by objects of different types), the
- formal parameters assume many forms and can be referred to as polymorphic.
- Strachey did define polymorphism in passing, he didn't give elaborate
- technical definitions that I'm aware of. Its a shame he's not around to
- discuss his intentions further.
-
- >objsys> I disagree. Polymorphic really refers to objects that can
- >objsys> assume many forms; this was standard usage (and the "morphemic"
- >objsys> definition) long before Strachey.
- >
- >You are right in this, but Strachey redefined 'polymorphic' in the
- >context of technical discussions on typing, so by now 'polymorphic'
- >usually is meant to extend only to proper and ad-hoc polymorphism for
- >procedures (except in special cases like value polymorphism, in the
- >sense of values that can change shape).
-
- Not true. Most static OO languages equate polymorphism with dynamic
- binding. For instance in the C++ ARM (p209): "... the ability to call
- a variety of functions using exactly the same interface - as is provided
- by virtual functions - is sometimes called polymorphism."
-
- Or even better, try Eiffel [Meyer 88:p224] ""Polymorphism" means the ability
- to take several forms. In object-oriented programming, this refers to the
- ability of an entity to refer at run-time to instances of various classes.
- In a typed environment such as Eiffel, this is constrained by inheritance:..."
-
- This is almost identical to my proposed definition [by coincidence, BTW]
- and is also almost identical to the definition quoted from Booch, below.
-
- > On the other hand I think
- >that 'polymorphism' is not used everywhere it should; I would call
- >'compiletime polymorphism' what others call 'templates'.
-
- Cardelli and Wegner (85) even equate/rename parametric polymorphism as
- generics/templates, so you're not the first. Generics clearly provide a
- static parametric case of polymorphism.
-
- >objsys> In a nutshell, polymorphism is the ability of an object to be a
- >objsys> placeholder (or formal object) for many different objects, and
- >objsys> for that formal object to behave differently based on the actual
- >objsys> object present.
- >
- >What you actually wrote is actually more like the ability of an *object*
- >to change class (as in Self), which is quite a different thing from the
- >ability of a variable to denote objects of different classes.
-
- That's not what I wrote; I wrote and meant the case of assignment. I've
- unified the two cases now, although I think "becomes" is really a special
- case of polymorphism. Most modern languages (I already gave references)
- use polymorphism to refer to the ability of an object to assume (or be
- assigned to) many different forms of objects (Meyer is quite clear on this),
- and the ability for an object to change itself, as opposed to an explicit
- external assignment to a reference to an object, makes things much simpler
- but can be viewed as a variation on the theme.
-
- >obj> class D: public B{};
- >obj>
- >obj> D d;
- >obj>
- >obj> b = d; // b is an object, not a formal object, and d is sliced
- >obj> rb = &d; // rb is a formal object (and hence, polymorphic) ref to d.
- >
- >This example really confirms me in my opinion that your notion of
- >'formal object' is really that of 'variable that can denote objects of
- >different classes', as in 'variables with latent/dynamic typing'.
-
- [It also confirms presentation is not programming, since rb was a reference
- and in C++ must be initialized with its antecedent!]
-
- Absolutely, as do most languages designers, although I am quite familiar with
- the "becomes" facility. Even Smalltalk defines it.
-
- >It is true that latent typing, whether bounded/inclusive or not, is the
- >norm in many OO languages, but also in many non OO ones. It is also true
-
- True, but the classical OO definition of polymorphism, or what Booch
- simply defines as polymorphism [Booch 91, p517] is: "A concept in type
- theory, according to which a name (such as a variable declaration) may
- denote objects of many different classes that are related by some common
- superclass; thus, any object denoted by this name is able to respond to
- some common set of operations in different ways."
-
- Again, the fact that OO has polymorphism does not infer that polymorphism
- is unique to OO, although the common structure in OO is usually defined in
- terms of class membership. And again, Booch and Meyer's definitions seem
- to be awfully close to mine.
-
- >that latent typing results in both overloading and polymorphism, but
- >this is more a side effect than an essential characteristic. I have the
-
- I show below why polymorphism is not a side-effect of latent typing.
-
- >feeling that most languages with latent typing of variables are such
- >because this avoided the trouble of defining a proper static checker,
- >and declaring each variable, when inferential type checkers a la
- >ML/Russell did not yet exist.
-
- This may have been the reason why Smalltalk is statically typeless, but
- dynamic typing is required in many circumstances. Programmers must implement
- such facilities themselves if a language does not provide support for such
- cases, which undesirably adds to program complexity and size.
-
- >I would find it rather hard to agree with those who say that latent
- >typing of variables is an essential aspect of an OO language, as IMNHO
- >one can still apply the OO paradigm without it.
-
- I think that depends on what you mean by the OO paradigm. Many consider
- dynamic binding (and hence polymorphism) to be a requirement of object-
- orientation, possibly deriving in origin from something like C+W's (85) 3rd
- criterion for an OO programming language:
-
- - Types [classes] may inherit attributes from supertypes [superclasses].
-
- where overriding can occur with specialized attributes in almost all OO
- languages.
-
- >objsys> But this occurs for polymorphic objects, not just formal
- >objsys> parameters. See the paper on Emerald (sorry, don't have the ref
- >objsys> with me) for their approach to polymorphic objects; its one
- >objsys> among many.
- >
- >Indeed these guys do not describe object polymorphism; the describe the
- >ability of a variable to denote objects of different classes (and if
- >they call it 'object polymorphism' they are as guilty as you are of
- >inflicting confusing terminology on the public).
-
- I think you're the one inflicting confusing terminology. Everyone in recent
- history seems to define polymorphism as a property of objects (Stroustrup,
- Meyer, Booch, ...) and I've never seen anyone equate polymorphism with
- structural and behavioral replacement alone - noone, never, anywhere - except
- you. That doesn't mean that everyone else is right and that you're wrong,
- but this requires some thought and requires you to really prove your case.
-
- >This has nothing to do with OO programming, and with objects. Let me
- >insist (I hope that repetition works) that it usually called
- >'latent/dynamic typing', as in Lisp for example, not 'object
- >polymorphism'; I have seen the latter term denoting the ability of an
- >object to change its class and therefore its shape after it has been
- >created, as is possible in Self.
-
- Can you provide references? I have never seen such terminology, although
- I have provided many, many cases where object polymorphism is used as I have
- defined it. I've seen "behavioral replacement" used to name a "becomes"
- facility [Kim 89], but never polymorphism.
-
- Lets look at the real world. There is some class of objects, B, that can
- have many forms, lets assume as given the case that they don't change once
- a particular form is taken. Now lets define some kinds of forms that a B
- can take, and call these classes D1, D2, ... Now take the case of where any
- of the D's can occur. In the sciences, B is refered to as "polymorphic" or
- as a "polymorphic object". I can declare a B object that can stand for any
- of the D forms. Since B can take on many differing forms, it is defined as
- "polymorphic". The property that B can assume different forms (and not the
- ability to become other forms, as in metamorphosis) is the canonical use of
- the term polymorphism. So sorry, it doesn't look as though structural and
- behavioral replacement (or a becomes facility) is the standard usage of the
- term polymorphism.
-
- This is also how most OO literature defines polymorphism. You call this
- latent/dynamic typing, although I clearly disagree with the dynamic typing
- part, because dynamic binding can occur with static typing. Since I believe
- OO languages should support structural and behavioral replacement, I should
- be an easy one to convince, yet convinced I am not, since based on the
- canonical use of term polymorphism in both the natural and computer science
- literatures, I believe you are wrong.
-
- bob
- objsys@netcom.com
-