Re: Defining polymorphism vs. overloading

mmengel@cuuxb.ATT.COM (~XT6561110~Marc Mengel~C25~M27~6184~)
11 Sep 90 15:53:04 GMT

          From comp.compilers

Related articles
[9 earlier articles]
Re: Defining polymorphism vs. overloading pase@orville.nas.nasa.gov (1990-09-06)
Re: Defining polymorphism vs. overloading tub!wg@relay.EU.net (1990-09-06)
Re: Defining polymorphism vs. overloading pase@orville.nas.nasa.gov (Douglas M. Pase) (1990-09-06)
Re: Defining polymorphism vs. overloading ok@goanna.cs.rmit.OZ.AU (1990-09-07)
Re: Defining polymorphism vs. overloading pardo@cs.washington.edu (1990-09-07)
Re: Defining polymorphism vs. overloading pardo@cs.washington.edu (1990-09-07)
Re: Defining polymorphism vs. overloading mmengel@cuuxb.ATT.COM (1990-09-11)
Re: Defining polymorphism vs. overloading freek@fwi.uva.nl (1990-09-10)
Re: Defining polymorphism vs. overloading pcg@cs.aber.ac.uk (Piercarlo Grandi) (1990-09-13)
Re: Defining polymorphism vs. overloading voss@suna0.cs.uiuc.edu (1990-09-14)
Re: Defining polymorphism vs. overloading stt@inmet.inmet.com (1990-09-15)
Re: Defining polymorphism vs. overloading px@fctunl.rccn.pt (1990-09-20)
Re: Defining polymorphism vs. overloading pcg@compsci.aberystwyth.ac.uk (Piercarlo Grandi) (1990-09-20)
[1 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: mmengel@cuuxb.ATT.COM (~XT6561110~Marc Mengel~C25~M27~6184~)
Keywords: polymorphism
Organization: AT&T National Technical Support Center
References: <9008310419.AA06194@karakorum.berkeley.edu> <PX.90Sep3180926@hal.fctunl.rccn.pt>
Date: 11 Sep 90 15:53:04 GMT

Okay. Time to settle this once and for all :-)


Polymorphism (poly == many,morph == type) i.e. many-type-ism;
is one operation that works on all (or at least many)
types.


Overloading is having the same token represent different operations.


I am using "operation" here in a general sense; certainly integer and
floating point addition are mechanically different in detail, yet for the
"same" values (i.e. 5.0 + 5.0 and 5 + 5) an addition operator will yeild the
"same" result (i.e. 10.0 and 10), floating point and integer addition are
then the "same" operation.


So if you're going to be polymorphic, you need to define what the operation
is, and pick one that makes sense accross the set of types you are dealing
with. You could for example define "<=" as a partial order on basically any
type and still have a consistent operator which a sorting algorithm would
work on for example.


Overloading is when the same token stands for different operations
altogether (i.e. "<<" being used for both bit shifts and standard I.O. in
C++). This is (IMHO) a Bad Thing. Overloading (as per my definition anyway
:-)) is something that makes code difficult if not impossible to read,
especially when pushed to the limit.


Polymorphism, on the other hand makes code easier to read, as it gets rid of
things like having both a "div" and "/" operator in Pascal.


[Incidentally, to soundly thump the dead horse of subscription in C, please
remember that "a[b]" in C is eqivalent to "*(a+b)" and that it is the "+"
operator on pointers and integers that is polymorphic, and always yeilds the
pointer address plus the integer times the size of the object the pointer
points to.]
--
Marc Mengel mmengel@cuuxb.att.com
attmail!mmengel
...!{lll-crg|att}!cuuxb!mmengel


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.