terminological obscurity

nnes pruebauno at latinmail.com
Mon May 31 18:26:36 EDT 2004


Arthur <ajsiegel at optonline.com> wrote in message news:<1r9ta017o5n64gman6mkt2ufg4v6m2tv1u at 4ax.com>...
> On Fri, 21 May 2004 13:30:23 -0700, Shalabh Chaturvedi
> <shalabh at cafepy.com> wrote:
> 
> >I believe it is conceptual homogeneity and not type homogeneity that
> >characterises the difference between lists and tuples.
> 
> "conceptual homogeneneity" defined  - as far as I see it - by
> reference to whether a rational Python programmer would group the
> objects together in a list.
> 
> A perfect tautology.
> 
> Which always seems to me to create more confusion, than clarification.
> 
> Art

Generaly speaking two objects "ham" and "spam" are of the same (duck)
"type" in context "a" to "b" of a program if all the methods of "ham"
used between "a" and "b" can be used with "spam" and all methods of
"spam" used between "a" and "b" can be used with "ham".

Example:

ham=' Arizona '
spam=['C','o','l','o','r','a','d','o']
print type(ham)
print type(spam)

#line a ---------

print ham.index('o')
print spam.count('o')
#Does work
#print spam.index('o')
#print ham.count('o')

#line b ---------

print ham.strip()
print spam.pop(0)
#Does not work
#print spam.strip()
#print ham.pop(0)

#line c ------
#EOF


ham and spam are of the same "type" in context a-b.
ham and spam are of different "type" in context b-c.

A list should be used to store ham and spam in context a-b.
A tuple should be used to store ham and spam in context b-c.

Of course "real type" of ham is 'str' and of spam is 'list' but that
is irrelevant when considering "duck typing".

"duck typing" is achieved in java by using interfaces, including the
relevant methods in them and casting the objects at the appropiate
context to that interface. So using java lingo we might translate the
previous to:

Lists are used if an usefull interface with common methods for the
objects can be created.

Tuples are used if no common interface can be created for the objects
stored.

NN

Disclaimer: The previous is my personal opinion and may change in the
future!

PS: Just in case you feel temped to ask me the forbidden question:
Which is better, duck typing or explicit typing? Answer: I don't know!



More information about the Python-list mailing list