definition of 'polymorphism' and python

G

Gabriel Zachmann

I understand the Wikipedia article on Polymorphism
( http://en.wikipedia.org/wiki/Polymorphism_(computer_science) )
that it doesn't make sense to talk about polymorphism in a fully dynamically
typed language -- does the Python community agree?

cheers,
gabriel.

--
/-----------------------------------------------------------------------\
| Any intelligent fool can make things bigger, more complex, |
| or more violent. It takes a touch of genius - and a lot of courage - |
| to move in the opposite direction. (Einstein) |
\-----------------------------------------------------------------------/
 
S

Steven D'Aprano

Maybe you should articulate your objection instead of letting others
guess what you might think?

In fairness, it is possible that Gabriel doesn't have any objects, because
he doesn't have an opinion yet.

Speaking for myself, I found that the first half of the article so
jargon-ridden that my brain rebooted seven times trying to read it, but
the section "Example" was so clear and simple that I now feel myself to be
an expert on polymorphism and am confident enough to give my opinion with
no fear of contradiction by any right-thinking Python programmer.

[deadpan]


But seriously... Python objects are strongly typed. Python will allow all
six of the examples of addition from the Example section. Since this is
supposed to be an example of polymorphism, and Python will do that exact
thing, then absolutely I would describe Python as polymorphic.

Well, that is, I would describe Python as polymorphic if I thought there
was any value to the term *wink*
 
B

Ben Sizer

Gabriel said:
I understand the Wikipedia article on Polymorphism
( http://en.wikipedia.org/wiki/Polymorphism_(computer_science) )
that it doesn't make sense to talk about polymorphism in a fully dynamically
typed language -- does the Python community agree?

"In computer science, polymorphism means allowing a single definition
to be used with different types of data (specifically, different
classes of objects)."
len("abcd") 4
len([1,2,3,4,5,6])
6

Looks pretty polymorphic to me. In fact, Python's polymorphism support
is so good that it makes inheritance much less important than it is in
other languages.
 
G

gene tani

Grant said:


Excellent. Maybe we can have a gentleman's agreement to confine all
unfocused arguments about following terms to Artima.com and C2 wiki

Strong, weak, static, dynamic, latent, duck typing
polymorphism, encapsulation, delegation,

;-}
 
M

Mike Meyer

gene tani said:
Excellent. Maybe we can have a gentleman's agreement to confine all
unfocused arguments about following terms to Artima.com and C2 wiki
Strong, weak, static, dynamic, latent, duck typing
polymorphism, encapsulation, delegation,

How about we add "Call by FOO", for any FOO?

<mike
 
B

bruno at modulix

Gabriel said:
I understand the Wikipedia article on Polymorphism
( http://en.wikipedia.org/wiki/Polymorphism_(computer_science) )
that it doesn't make sense to talk about polymorphism in a fully
dynamically typed language

"a single polymorphic operator can act in expressions of various types"
list1 = [1,2,3]
list2 = [4,5,6]
list1 + list2 [1, 2, 3, 4, 5, 6]
int1 = 1
int2 = 2
int1 + int2 3
str1 = "aaa"
strb = "bbb"
str1 + strb 'aaabbb'

Ok, so we have polymorphic operators (if that wasn't obvious)

"A function that can evaluate to and be applied to values of different
types is known as a polymorphic function."

Ok, so we have polymorphic functions too (if that wasn't obvious...)

"If all code is written without mention of any specific type and thus
can be used transparently with any number of new types, it is called
parametric polymorphism"

Well, seems that's what we (mostly) have

-- does the Python community agree?

I'm not the Python communauty, but I think you already guessed my answer !-)
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top