Polymorphism

R

Roedy Green

Roedy, you're wrong on this. Don't confuse the newbies.

Here is my new definition:

The generic term meaning having many forms. You can use the same name
for several different things and the compiler automatically figures
out which version you wanted. There are several types of polymorphism
supported in Java, shadowing, overriding, and overloading. Though the
term polymorphic means literally "having many forms", most computer
scientists don't include overloading as polymorphism, just overriding.
Perhaps this is because overriding is much more difficult to implement
and they don't want to dilute the achievement.
 
B

Ben Wilson

Ben Wilson said:
You missed something. Objects s and l are Strings and ArrayLists in one
method and are accessed through variables of type Object in another. This is
definitely polymorphism.

Ahem, what I meant to say, was, this is at best inheritance, not
polymorphism. :)
 
R

Roedy Green

Ahem, what I meant to say, was, this is at best inheritance, not
polymorphism. :)

So what instance methods do is polymorphism, but what static methods
do is inheritance?
 
B

Ben Wilson

Roedy Green said:
So what instance methods do is polymorphism, but what static methods
do is inheritance?

Ummm... As I understand, polymorphism is relevant to inheritance only
insofar as method names are actually being overridden. I suppose you'd say
that if I had class A and class B and B extended A, you have inheritance.
You'd only speak of polymorphism if B went and overrode one of A's methods.
Static methods don't override the parent class, but do this
hiding-shadow-thing.

It seems you've revised your opinion on the applicability of the term
"polymorphism" to overloading. Are you now questioning the applicability of
the term to this hiding-shadow-thing, or are you looking for a proper word
to describe "what static methods do"?

B.
 
T

Thomas G. Marshall

Roedy Green said:
Here is my new definition:

The generic term meaning having many forms. You can use the same name
for several different things and the compiler automatically figures
out which version you wanted. There are several types of polymorphism
supported in Java, shadowing, overriding, and overloading. Though the
term polymorphic means literally "having many forms", most computer
scientists don't include overloading as polymorphism, just overriding.
Perhaps this is because overriding is much more difficult to implement
and they don't want to dilute the achievement.


er......still not there. I posed this question in comp.object under the
subject

Is "AD-HOC polymorphism" actually Polymorphism?

And I got a very good response:

Section 1.3
"On Understanding Types, Data Abstraction, and
Polymorphism" Computing Surveys, Vol 17 n. 4,
pp 471-522, December 1985
http://research.microsoft.com/Users/luca/Papers/OnUnderstanding.A4.pdf

Base your definition upon that pdf's section 1.3.
 
T

Thomas G. Marshall

Ben Wilson said:
Ummm... As I understand, polymorphism is relevant to inheritance only
insofar as method names are actually being overridden. I suppose
you'd say that if I had class A and class B and B extended A, you
have inheritance. You'd only speak of polymorphism if B went and
overrode one of A's methods.

/Almost/. Dynamically typed languages do not need inheritance for
polymorphism to exist.
 
X

xarax

David Hilsee said:
The term "polymorphism" can apply to compile-time polymorphism or runtime
polymorphism (aka "dynamic binding"). Many people will use the term
"polymorphism" to refer to dynamic binding, but that doesn't mean that the
term can't also be used to refer to compile-time constructs like
overloading. For example, C++ templates are sometimes called compile-time
polymorphism.

And that is a mistake, too. Templates are correctly
called "Templates" or "Generics" or "Genericity". While
templates support polymophism, templates are *not*
polymorphism. Support polymorphism is when the template
accepts a type specification, like "List<String>", which
constrains the acceptable types (checked at compile-time)
that the List may contain.

Signature overloading is different from templates, which
are different from polymorphism. Three different concepts.
 
X

xarax

Thomas G. Marshall said:
er......still not there. I posed this question in comp.object under the
subject

Is "AD-HOC polymorphism" actually Polymorphism?

And I got a very good response:

Section 1.3
"On Understanding Types, Data Abstraction, and
Polymorphism" Computing Surveys, Vol 17 n. 4,
pp 471-522, December 1985
http://research.microsoft.com/Users/luca/Papers/OnUnderstanding.A4.pdf

Base your definition upon that pdf's section 1.3.

Well, that's a rather geeky definition in that pdf file. Easier
to understand is how Bertrand Meyer describes object oriented
concepts in his book, "Object Oriented Software Construction", 2nd
edition, http://archive.eiffel.com/doc/oosc/

This is the bible for learning OOP.
 
S

Stefan Ram

Thomas G. Marshall said:
/Almost/. Dynamically typed languages do not need inheritance for
polymorphism to exist.

A message is sent to an object, and that object is specified
by an expression.

expression.message( arguments )

Depending on the value of that expression, the receiver will
be determined; possibly late at runtime.

Possibly, the class (the form, the "morph") of the receiver is
not known until that determination. When there is more than
one ("poly-") possibility, the receiver is "polymorph".

In languages with static types, in order for this to be
allowed, all those types must be of a subtype of the type of
the expression. That's when inheritance (or
interface-implementation) is needed in Java.

In languages without static types, there is no need for
inheritance. The receiver, however, needs to be able to
understand the message sent. If not, a runtime "error" might
occur.

Depending on their type (class, form [morph]), different
receivers might have different interpretations ("methods") of
the same message.

One might go to two different restaurants and give the same
message to the waiter (order the dish with the same name) and
might get two different meals. If one wants to order a french
dish and makes sure that the restaurants receiving the message
indeed are of the type "french", one can be sure to get at
least something; which might still depend on the subtype of
the restaurant. The menu serves as the interface
specification, the kitchen is the implementation - usually
hidden.
 
R

Roedy Green

er......still not there. I posed this question in comp.object under the
subject

This what happens when you try to highjack an establish term for some
new purpose. You can get away with it when the term has no other
logical meaning in your domain, e.g. "spawn", but that is not the
case here. Polymorphism already had a meaning inherited from
mathematics.

The OED defines polymorphism as multiform esp. biology varying
individuals, passing through successive variations, also called by
several different names.

Polymorphism has a very broad meaning obvious from its Greek roots.
To try to abscond with the term for something very specific was
foolish. You can see the confusion it lead to.

Polymorphism is a well established term in mathematics. Use of it
this way was an error even if that is the current consensus on the
definition.

It makes about as much sense as calling it polyamory.
 
R

Roedy Green

It seems you've revised your opinion on the applicability of the term
"polymorphism" to overloading. Are you now questioning the applicability of
the term to this hiding-shadow-thing, or are you looking for a proper word
to describe "what static methods do"?

Obviously I have to defer to what he official definitions are.
However, I am still of the opinion polymorphism already has a
definition inherited from mathematics and therefore it is arrogant to
redefine it, especially in such a narrow way which violates the
literal meaning very broad of the word in ordinary contexts.

It comes from the Greek for "many forms". Its new definition is much
narrower than that.

**** it. Let them the screw the English language. I am tired of
getting into fights. No matter what I say, people will immediately
argue the opposite just to enjoy a fight.
 
T

Thomas G. Marshall

Roedy Green said:
On Mon, 02 Aug 2004 00:02:42 GMT, "Thomas G. Marshall"



This what happens when you try to highjack an establish term for some
new purpose. You can get away with it when the term has no other
logical meaning in your domain, e.g. "spawn", but that is not the
case here. Polymorphism already had a meaning inherited from
mathematics.

So what? Polymorphism has a meaning specific to computer science, and you
just did not find it yet.
 
T

Thomas G. Marshall

Stefan Ram said:
"Thomas G. Marshall"
/Almost/. Dynamically typed languages do not need inheritance for
polymorphism to exist.

A message is sent to an object, and that object is specified
by an expression.

expression.message( arguments )

Depending on the value of that expression, the receiver will
be determined; possibly late at runtime.

Possibly, the class (the form, the "morph") of the receiver is
not known until that determination. When there is more than
one ("poly-") possibility, the receiver is "polymorph".

In languages with static types, in order for this to be
allowed, all those types must be of a subtype of the type of
the expression. That's when inheritance (or
interface-implementation) is needed in Java.

In languages without static types, there is no need for
inheritance. The receiver, however, needs to be able to
understand the message sent. If not, a runtime "error" might
occur.

Depending on their type (class, form [morph]), different
receivers might have different interpretations ("methods") of
the same message.

One might go to two different restaurants and give the same
message to the waiter (order the dish with the same name) and
might get two different meals. If one wants to order a french
dish and makes sure that the restaurants receiving the message
indeed are of the type "french", one can be sure to get at
least something; which might still depend on the subtype of
the restaurant. The menu serves as the interface
specification, the kitchen is the implementation - usually
hidden.

no argument with any of this...
 
D

David Hilsee

Thomas G. Marshall said:
So what? Polymorphism has a meaning specific to computer science, and you
just did not find it yet.

While I agree that terms may have different meanings in different domains, I
think that the term "polymorphism" means different things to different
people, even if those people are talking about programming constructs or
computer science. That's probably why there so much discussion has been
generated over a single term. I agree that math's usage of "polymorphism"
is not necessarily relevant, even though math and computers go hand-in-hand.
Personally, I take any reference to "polymorphism" as the run-time (via
inheritance) variety, unless the person using the term gives me a reason to
suspect that he/she means otherwise.
 
J

Jim Cochrane

While I agree that terms may have different meanings in different domains, I
think that the term "polymorphism" means different things to different
people, even if those people are talking about programming constructs or
computer science. That's probably why there so much discussion has been
generated over a single term. I agree that math's usage of "polymorphism"
is not necessarily relevant, even though math and computers go hand-in-hand.
Personally, I take any reference to "polymorphism" as the run-time (via
inheritance) variety, unless the person using the term gives me a reason to
suspect that he/she means otherwise.

Perhaps it's safer to use the term dynamic binding for this, since there
appears to be a lot of disagreement on the precise definition of polymorphism.
 
T

Thomas G. Marshall

Jim Cochrane said:
Perhaps it's safer to use the term dynamic binding for this, since
there appears to be a lot of disagreement on the precise definition
of polymorphism.

Yes. IMHO, it's best to keep /inheritance/ out of it.
 
T

thufir.hawat

On Mon, 2 Aug 2004, Roedy Green wrote:
[..]
It comes from the Greek for "many forms". Its new definition is much
narrower than that.

**** it. Let them the screw the English language. I am tired of
getting into fights. No matter what I say, people will immediately
argue the opposite just to enjoy a fight.

don't you mean greek language?
 
D

David Hilsee

On Mon, 2 Aug 2004, Roedy Green wrote:
[..]
It comes from the Greek for "many forms". Its new definition is much
narrower than that.

**** it. Let them the screw the English language. I am tired of
getting into fights. No matter what I say, people will immediately
argue the opposite just to enjoy a fight.

don't you mean greek language?

Greek, or geek? *grin*
 
X

xarax

Roedy Green said:
This what happens when you try to highjack an establish term for some
new purpose. You can get away with it when the term has no other
logical meaning in your domain, e.g. "spawn", but that is not the
case here. Polymorphism already had a meaning inherited from
mathematics.

The OED defines polymorphism as multiform esp. biology varying
individuals, passing through successive variations, also called by
several different names.

Polymorphism has a very broad meaning obvious from its Greek roots.
To try to abscond with the term for something very specific was
foolish. You can see the confusion it lead to.

Polymorphism is a well established term in mathematics. Use of it
this way was an error even if that is the current consensus on the
definition.

It makes about as much sense as calling it polyamory.

I have the same complaint about Java hi-jacking the
term "serialization". In computer science for decades
before Java appeared, "serialization" means what Java
thinks is "synchronization". When a process or thread
"serializes", it is synchronizing its processing with
another process or thread.

There's not much consensus on the computer science term
that would mean what Java thinks is "serializing". In
the mainframe world, it is sometimes called "unloading",
and Java "de-serializing" would be called "reloading".
Also, the term "persistence" comes to mind.

So, in the non-Java world, "serializing" causes two
or more processes or threads to proceed in a "serial"
manner (as opposed to concurrent or parallel) through
the use of mutex (mutual exclusion) interface.
 
X

xarax

David Hilsee said:
On Mon, 2 Aug 2004, Roedy Green wrote:
[..]
It comes from the Greek for "many forms". Its new definition is much
narrower than that.

**** it. Let them the screw the English language. I am tired of
getting into fights. No matter what I say, people will immediately
argue the opposite just to enjoy a fight.

don't you mean greek language?

Greek, or geek? *grin*

Will someone please mention Hitler, so this
thread will cease?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,785
Latest member
undedgini

Latest Threads

Top