home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / object / 4986 < prev    next >
Encoding:
Text File  |  1993-01-21  |  10.8 KB  |  208 lines

  1. Newsgroups: comp.object
  2. 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
  3. From: Bob Hathaway <objsys@netcom.com>
  4. Subject: Re: FAQ  Part 1 (of 2) [ polymorphism or latent typing? ]
  5. Message-ID: <1993Jan22.004420.16674@netcom.com>
  6. Sender: objsys@netcom.com (Object Systems)
  7. Organization: Object Systems
  8. References: <1993Jan13.061114.18430@netcom.com> <PCG.93Jan20002119@decb.aber.ac.uk>
  9. Date: Fri, 22 Jan 1993 00:44:20 GMT
  10. Lines: 196
  11.  
  12. In article <PCG.93Jan20002119@decb.aber.ac.uk>, pcg@aber.ac.uk (Piercarlo Grandi) writes:
  13. >The discussion on polymorphism is in another article, but let me
  14. >register here my deep dissent over the idea that variables (or even
  15. >worse, objects, except wheere they can change class over time) can be
  16. >polymorphic; procedure implementations only can be polymoprphic
  17. >(procedure interfaces too if one accepts the misleading but popular term
  18. >"ad hoc polymorphism").
  19.  
  20. This is only with your procedural view of object-orientation.  Polymorphic
  21. objects are the rule in an object-oriented [read "strong equivalence"] view,
  22. which I believe is preferred as pointed out in my previous posting.  Also,
  23. [I have done work in this area], the cases of objects becoming and assuming
  24. (through something like pointer semantics) other objects can be unified, as
  25. I have done in my definition of polymorphism.  In use there is a difference
  26. (assigning or becoming), but not in definition.  Also, I show below that the
  27. canonical use of the term "polymorphism" refers to objects that can assume
  28. (be assigned to) many objects and does *not* usually refer to objects that
  29. can become (or change themselves into) other objects.  This is more of
  30. an interesting special case, usually referred to as metamorphosis and not
  31. polymorphism, as I recall.
  32.  
  33. >I think that by polymorphic variables you mean variables that are not
  34. >restricted at compile time to denote values of one class only, as in
  35. >the various cases (bounded, unbounded) of latent "typing".
  36.  
  37. But this is polymorphism in programming, since it is objects assuming or
  38. becoming many different objects, or the essence of polymorphism.  If achieved
  39. thru latent typing, fine.  Since Strachey defined parametrically polymorphic
  40. functions (functions parameterized by objects of different types), the
  41. formal parameters assume many forms and can be referred to as polymorphic.
  42. Strachey did define polymorphism in passing, he didn't give elaborate
  43. technical definitions that I'm aware of.  Its a shame he's not around to
  44. discuss his intentions further.
  45.  
  46. >objsys> I disagree.  Polymorphic really refers to objects that can
  47. >objsys> assume many forms; this was standard usage (and the "morphemic"
  48. >objsys> definition) long before Strachey.
  49. >
  50. >You are right in this, but Strachey redefined 'polymorphic' in the
  51. >context of technical discussions on typing, so by now 'polymorphic'
  52. >usually is meant to extend only to proper and ad-hoc polymorphism for
  53. >procedures (except in special cases like value polymorphism, in the
  54. >sense of values that can change shape).
  55.  
  56. Not true.  Most static OO languages equate polymorphism with dynamic
  57. binding.  For instance in the C++ ARM (p209): "... the ability to call
  58. a variety of functions using exactly the same interface - as is provided
  59. by virtual functions - is sometimes called polymorphism."
  60.  
  61. Or even better, try Eiffel [Meyer 88:p224] ""Polymorphism" means the ability
  62. to take several forms.  In object-oriented programming, this refers to the
  63. ability of an entity to refer at run-time to instances of various classes.
  64. In a typed environment such as Eiffel, this is constrained by inheritance:..."
  65.  
  66. This is almost identical to my proposed definition [by coincidence, BTW]
  67. and is also almost identical to the definition quoted from Booch, below.
  68.  
  69. >                                             On the other hand I think
  70. >that 'polymorphism' is not used everywhere it should; I would call
  71. >'compiletime polymorphism' what others call 'templates'.
  72.  
  73. Cardelli and Wegner (85) even equate/rename parametric polymorphism as
  74. generics/templates, so you're not the first.  Generics clearly provide a
  75. static parametric case of polymorphism.
  76.  
  77. >objsys> In a nutshell, polymorphism is the ability of an object to be a
  78. >objsys> placeholder (or formal object) for many different objects, and
  79. >objsys> for that formal object to behave differently based on the actual
  80. >objsys> object present.
  81. >
  82. >What you actually wrote is actually more like the ability of an *object*
  83. >to change class (as in Self), which is quite a different thing from the
  84. >ability of a variable to denote objects of different classes.
  85.  
  86. That's not what I wrote; I wrote and meant the case of assignment.  I've
  87. unified the two cases now, although I think "becomes" is really a special
  88. case of polymorphism.  Most modern languages (I already gave references)
  89. use polymorphism to refer to the ability of an object to assume (or be
  90. assigned to) many different forms of objects (Meyer is quite clear on this),
  91. and the ability for an object to change itself, as opposed to an explicit
  92. external assignment to a reference to an object, makes things much simpler
  93. but can be viewed as a variation on the theme.
  94.  
  95. >obj>   class D: public B{};
  96. >obj> 
  97. >obj>   D d;
  98. >obj> 
  99. >obj>   b = d;    // b is an object, not a formal object, and d is sliced
  100. >obj>   rb = &d;  // rb is a formal object (and hence, polymorphic) ref to d.
  101. >
  102. >This example really confirms me in my opinion that your notion of
  103. >'formal object' is really that of 'variable that can denote objects of
  104. >different classes', as in 'variables with latent/dynamic typing'.
  105.  
  106. [It also confirms presentation is not programming, since rb was a reference
  107. and in C++ must be initialized with its antecedent!]
  108.  
  109. Absolutely, as do most languages designers, although I am quite familiar with
  110. the "becomes" facility.  Even Smalltalk defines it.
  111.  
  112. >It is true that latent typing, whether bounded/inclusive or not, is the
  113. >norm in many OO languages, but also in many non OO ones. It is also true
  114.  
  115. True, but the classical OO definition of polymorphism, or what Booch
  116. simply defines as polymorphism [Booch 91, p517] is:  "A concept in type
  117. theory, according to which a name (such as a variable declaration) may
  118. denote objects of many different classes that are related by some common
  119. superclass; thus, any object denoted by this name is able to respond to
  120. some common set of operations in different ways."
  121.  
  122. Again, the fact that OO has polymorphism does not infer that polymorphism
  123. is unique to OO, although the common structure in OO is usually defined in
  124. terms of class membership.  And again, Booch and Meyer's definitions seem
  125. to be awfully close to mine.
  126.  
  127. >that latent typing results in both overloading and polymorphism, but
  128. >this is more a side effect than an essential characteristic. I have the
  129.  
  130. I show below why polymorphism is not a side-effect of latent typing.
  131.  
  132. >feeling that most languages with latent typing of variables are such
  133. >because this avoided the trouble of defining a proper static checker,
  134. >and declaring each variable, when inferential type checkers a la
  135. >ML/Russell did not yet exist.
  136.  
  137. This may have been the reason why Smalltalk is statically typeless, but
  138. dynamic typing is required in many circumstances.  Programmers must implement
  139. such facilities themselves if a language does not provide support for such
  140. cases, which undesirably adds to program complexity and size.
  141.  
  142. >I would find it rather hard to agree with those who say that latent
  143. >typing of variables is an essential aspect of an OO language, as IMNHO
  144. >one can still apply the OO paradigm without it.
  145.  
  146. I think that depends on what you mean by the OO paradigm.  Many consider
  147. dynamic binding (and hence polymorphism) to be a requirement of object-
  148. orientation, possibly deriving in origin from something like C+W's (85) 3rd
  149. criterion for an OO programming language:
  150.  
  151.   - Types [classes] may inherit attributes from supertypes [superclasses].
  152.  
  153. where overriding can occur with specialized attributes in almost all OO
  154. languages.
  155.  
  156. >objsys> But this occurs for polymorphic objects, not just formal
  157. >objsys> parameters.  See the paper on Emerald (sorry, don't have the ref
  158. >objsys> with me) for their approach to polymorphic objects; its one
  159. >objsys> among many.
  160. >
  161. >Indeed these guys do not describe object polymorphism; the describe the
  162. >ability of a variable to denote objects of different classes (and if
  163. >they call it 'object polymorphism' they are as guilty as you are of
  164. >inflicting confusing terminology on the public).
  165.  
  166. I think you're the one inflicting confusing terminology.  Everyone in recent
  167. history seems to define polymorphism as a property of objects (Stroustrup,
  168. Meyer, Booch, ...) and I've never seen anyone equate polymorphism with
  169. structural and behavioral replacement alone - noone, never, anywhere - except
  170. you.  That doesn't mean that everyone else is right and that you're wrong,
  171. but this requires some thought and requires you to really prove your case.
  172.  
  173. >This has nothing to do with OO programming, and with objects. Let me
  174. >insist (I hope that repetition works) that it usually called
  175. >'latent/dynamic typing', as in Lisp for example, not 'object
  176. >polymorphism'; I have seen the latter term denoting the ability of an
  177. >object to change its class and therefore its shape after it has been
  178. >created, as is possible in Self.
  179.  
  180. Can you provide references?  I have never seen such terminology, although
  181. I have provided many, many cases where object polymorphism is used as I have
  182. defined it.  I've seen "behavioral replacement" used to name a "becomes"
  183. facility [Kim 89], but never polymorphism.
  184.  
  185. Lets look at the real world.  There is some class of objects, B, that can
  186. have many forms, lets assume as given the case that they don't change once
  187. a particular form is taken.  Now lets define some kinds of forms that a B
  188. can take, and call these classes D1, D2, ...  Now take the case of where any
  189. of the D's can occur.  In the sciences, B is refered to as "polymorphic" or
  190. as a "polymorphic object".  I can declare a B object that can stand for any
  191. of the D forms.  Since B can take on many differing forms, it is defined as
  192. "polymorphic".  The property that B can assume different forms (and not the
  193. ability to become other forms, as in metamorphosis) is the canonical use of
  194. the term polymorphism.  So sorry, it doesn't look as though structural and
  195. behavioral replacement (or a becomes facility) is the standard usage of the
  196. term polymorphism.
  197.  
  198. This is also how most OO literature defines polymorphism.  You call this
  199. latent/dynamic typing, although I clearly disagree with the dynamic typing
  200. part, because dynamic binding can occur with static typing.  Since I believe
  201. OO languages should support structural and behavioral replacement, I should
  202. be an easy one to convince, yet convinced I am not, since based on the
  203. canonical use of term polymorphism in both the natural and computer science
  204. literatures, I believe you are wrong.
  205.  
  206. bob
  207. objsys@netcom.com
  208.