terminological obscurity

?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Donn said:
Well, I'm not really sure what he has in mind there, so there
is some ambiguity for students of homogeneity such as ourselves.

I was trying to point out (and try again), that uniform typing and
homogeneity are *not* the same things, all the time. However, people
often consider them to be the same thing, and for a good reason:
In *most* applications, homogenous structures are uniformly typed,
and uniformly typed collections are typically homogenous.

Now, if someone brings up a collection which is homogenous, but
where elements have different most-specific types, it may still
be the case that the types share some common supertype. One way
of obtaining such a common supertype is the introduction of a
union type. However, this is about typing, not about homogeneity.

Regards,
Martin
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Arthur said:
Donn. who I think we agree, brought some light to this discussion did
state clearly, I think, that the use of the "homogenous data" (in
describing for example None and a module) is bad and misleading
terminolgy. Perhaps, because it supports too well a supposition that
we are only talking in tautologies. What can be said be homogenous
about such data, outside of the membership in a list?

It is obvious that a single piece of data, in itself, cannot be
homogenous. You have to pick a set of objects to determine whether
they are homogenous. However, they are NOT homogenous by the mere
fact that they are in set, and they are NOT homogenous by the fact
that they share all the same type. Instead, they share the same
semantical properties (whatever those are).

So: No, "homogenous data" is *NOT* a tautology. It refers to
inherent properties of the elements of the list, not to the
fact that they are members of the list. It is possible to create
a heterogenous list; the Python style suggests that you should
not do that.

If "lists are for homogenous data" was a tautology, the term
"heterogenous lists" would be a contradiction. However, it is
not: it is a meaningful term indeed.
Yet you insist, with a fresh start on all this, on using the
terminology "homogenous data".

I don't understand Martin any better thatn I understand Guido.

I don't see where I use the term in any new way in which
it hasn't been used before.

I *also* mentioned that Guido has talked about typing, and
explained how a list of differently-typed objects may still
get a single static type. However, static typing of lists
and homogenous lists (i.e. lists of homogenous data) are
different (although related) issues.

Regards,
Martin
 
D

Duncan Booth

Unless you want to use it as a key for a dictionary. Then use
a tuple.


:)

You missed a couple of other important cases where you need to use a tuple
rather than a list, even though the elements are homogenous:

isinstance takes as its second argument: a class, type or a tuple of things
it takes as its second argument.

try ... except expression, target: suite
The expression must be an exception class (or a string) or a tuple of
things that can appear as the expression here.

The common factor in both of these cases is that by only allowing tuples
instead of lists you can allow the expressions to nest to an arbitrary
degree, but never have to worry about infinite loops caused by cycles in
the data structure. (Although, stack overflow can still be a problem as
evidenced by the Python 2.3.4 release notes)
 
S

Steve Holden

Donn said:
Well for one, before new style classes, it was easier to think of an
"instance" as in some sense a pseudo data type. Instances of
different classes - even with no hierarchical relationship - were more
conceptually homogenous.

But with everything subclassable, 2 different classes, each derived
from object, are conceptually distinguished more similarly to the way
in which a str and int are distinguished.


Really makes no difference at all - not just insignificant,
really _no_ difference. A truly heterogeneous sequence may
be full of references to the _same_ object (e.g., (1, 1, 1)),
and a truly homogeneous sequence may have objects as different
as None and a module. It's not about properties of the objects,
considered in isolation.
Absolutely. See below.
GvR> I always think of the type of a list as "list of T" while I
GvR> think of a tuple's type as "tuple of length N with items of
GvR> types T1, T2, T3, ..., TN". So [1, 2] and [1, 2, 3] are both
GvR> "list of int" (and "list of Number" and "list of Object", of
GvR> course) while ("hello", 42) is a "2-tuple with items str and
GvR> int" and (42, "hello", 3.14) is a "3-tuple with items int,
GvR> str, float".

He sort of stacks the cards by making his tuples of hetereogenous
type, and his list easily described as a list of T. And thereby
sidesteps all the ambiguities inherent in the ten word edict. Except
that at the Object level, we are at lists of Objects and tuples of
Objects. It detracts little from the point of the above quote, but
this quote then becomes substantially weaker as support for his 10
worder.

While Arthur is possibly correct in the sense that "I can't argue with
that", he's also correct in the sense that "English and Python are both
languages".
Guess he may have overestimated his audience.
More likely he was speaking to a specific question, and is now being
taken out of context.
If you're interested in the history of this matter, it may
help to know that Guido did not invent the tuple. It has
been around in computer programming languages since Lisp.
You can actually find precisely parallel descriptions of
the concept in that context, down to the unnecessary use
of different data types to emphasize the heterogeneity.
Furthermore, all such implementations are probably based on the tuple as
used by mathematicians since God was a lad. A tuple is an ORDERED
collection of items, not necessarily of the same type.

The important thing about a mathematical tuple is that it is constructed
so that the position of an element in the tuple signifies its purpose.

The important thrust of this apparently endless discussion is to
highlight the possible need for some way *other than indexing* to get
information out of a tuple. Really, most places where tuples are used, a
programmer might find it more convenient to extract the elements as
attributes - by name rather than position - hence the changes to the
os.path.stat() return value in version 2.2. People got tired of
accessing the individual values by using the appropriate index.

I'm guessing (though in this forum I am likely to be proved wrong at
some length) that most uses of tuples could senibly be replaced by
simple "bunch"-type objects in the Alex Martelli sense:
.... def __init__(self, **kw):
.... self.__dict__.update(kw)
....
However it's a bit late to start insisting on this usage when the tuple
has been embedded in the language so long.

The thing that ticks me off is when I come across a module that INSISTS
I provide a tuple, when really a list would be perfectly adequate. This
often happens in database munging applications: retrieving data yields a
tuple (perfectly appropriate, as each column is potentially of its own
type). To add further information I have to convert this tuple to a list
and modify it. Can I write this list out using the DBAPI interface?
Well, usually I first have to convert it to a tuple, because most
database modules require a tuple. Frankly I wish they'd be a bit less
picky, and do the conversion themselves if they must.

Obviously it would also be helpful if DB values were accessible by
attribute name. The problem wtih that is one can't always guarantee that
SQL will name things in Python-compatible ways. For some reason, it
seems that database deigners (though probably the ones who exclusively
use GUIs) have a penchant for weird characters like spaces and pound
signs in their column names. Don't get me started ...
Lisp and its relatives have both a tuple and a list type,
but the list is a `real list', not a 1-dimension array as
in Python but a recursive data structure. In Python, this
data structure can be represented using a tuple:

t = (0, None)
t = (1, t)
t = (2, t)
...
def print_list(tail):
value, tail = tail
if tail:
print_list(tail)
print value

Guido's "mistake" is that unification of all these sequence
types leaves the distinctions less obvious.
While it's interesting for us all to discuss how many objects can dance
on the head of a pin, however, it probably won't be profitable. The
bottom line, for pragmatists, is that you can do 'most anything with a
list that you can with a tuple EXCEPT use it as a dictionary key.

Just as some people will do integer arithmetic using floating point
numbers, so some people will use lists where tuples might be more
appropriate.

Just as (sometimes) floating-point's inaccuracies will bite the careless
user in the ass, so (sometimes) will inappropriate use of lists (though
much less frequently).

regards
Steve
 
A

Arthur

So: No, "homogenous data" is *NOT* a tautology. It refers to
inherent properties of the elements of the list, not to the
fact that they are members of the list.

Is the random set of, say, 10 human beings homogeonous or
hetereogenous?

Or is that a meaningless question, as the answer depends purely on
context?

Are objects that have hundreds of attributes each, and that conform as
to a single attribute, which attibute accounts for there presence
together in a list, meaningfully homogenous - outside of the fact of
their presence together in the list?

Art
 
D

Donn Cave

Steve Holden said:
The important thrust of this apparently endless discussion is to
highlight the possible need for some way *other than indexing* to get
information out of a tuple. Really, most places where tuples are used, a
programmer might find it more convenient to extract the elements as
attributes - by name rather than position - hence the changes to the
os.path.stat() return value in version 2.2. People got tired of
accessing the individual values by using the appropriate index.

I'm guessing (though in this forum I am likely to be proved wrong at
some length) that most uses of tuples could senibly be replaced by
simple "bunch"-type objects in the Alex Martelli sense:

... def __init__(self, **kw):
... self.__dict__.update(kw)
...

However it's a bit late to start insisting on this usage when the tuple
has been embedded in the language so long.

Sure, the stat and tm structs are a good example of what they're
a good example of. Once a tuple has more than a handful of
elements, you're past the cognitive limit for really workable
tuples.

For tuples of more reasonable size, I think most of us prefer to
unpack. Even if I have to check on the order first, I'd rather
write
client, client_addr = service.accept()
for k, v in q.items:

etc. That's why the tuple has been embedded in the language so
long without sprouting these features, because it works well when
used well.

Donn Cave, (e-mail address removed)
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Arthur said:
Is the random set of, say, 10 human beings homogeonous or
hetereogenous?

If they are random, than yes, they are homogenous as they are
all human, and no, the are heterogenous, because they are
random, i.e. they share no features.
Or is that a meaningless question, as the answer depends purely on
context?

Not purely (as you can see above), but typically. You need some
application context to know whether a set of objects is homogenous -
with respect to properties that the application cares about.
Are objects that have hundreds of attributes each, and that conform as
to a single attribute, which attibute accounts for there presence
together in a list, meaningfully homogenous - outside of the fact of
their presence together in the list?

Likely: no. It may still be that there is external state that makes
them homogenous. E.g. they may all act as keys to some database, and
be kept in a single collection so the application can find all items
associated with the keys.

Regards,
Martin
 
A

Arthur

If they are random, than yes, they are homogenous as they are
all human, and no, the are heterogenous, because they are
random, i.e. they share no features.

But then nothing can be determined about the hetergenousity or the
homogenousity of any particular context for this data by reference to
the data itself.

Though the reverse is not true.

In the conversation I am having this is a significant point.

But I suspect we are not having the same conversation.

Art
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Arthur said:
But then nothing can be determined about the hetergenousity or the
homogenousity of any particular context for this data by reference to
the data itself.

Though the reverse is not true.

In the conversation I am having this is a significant point.

But I suspect we are not having the same conversation.

I'm uncertain. I would see a significant point if you would
admit that "a list is for homogenous data" is not a tautology.
You certainly need a context to make a statement about
homogeneity, but that context is *not* the mere fact that
the data are all stored in the list.

Regards,
Martin
 
A

Arthur

I'm uncertain. I would see a significant point if you would
admit that "a list is for homogenous data" is not a tautology.

I am not unwilling to make the admission, but I need some help.

Becasue I am not unwilling to see a list as an homogenous context. But
by placing data within that context we have done nothing to change the
nature of the data. If the data was ambiguous, it is still ambiguous.

The purpose of the list is a perspective on the data. From that
perspective we view an homogenous aspect of it.

Does that do?

But if something about type is in the end at the bottom of your view,
than I am still a bit lost, I am afraid.

Art
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Arthur said:
Becasue I am not unwilling to see a list as an homogenous context. But
by placing data within that context we have done nothing to change the
nature of the data. If the data was ambiguous, it is still ambiguous.

The purpose of the list is a perspective on the data. From that
perspective we view an homogenous aspect of it.

Does that do?

Almost. Except, in real life, it is vice versa: First, we have the
perspective, and then we decide to represent the data in a list.
But if something about type is in the end at the bottom of your view,
than I am still a bit lost, I am afraid.

People use the word "type" to mean different things. I try to use it
in what I consider the most generic sense, the one that is also
defined in ISO Open Distributed Processing:

"A type is a predicate"

In that definition "is green" is as much a type as "has used Python
to write software". In that sense, things in a list should share the
same type.

Other people use "type" to mean "class", but, in ODP terminology,
a class is a template: it can be used to create objects. Those
objects all share the same type, namely "is an instance of the
class". So, while classes do imply types, two objects that are
not instances of the same class may still have a same type.

Regards,
Martin
 
A

Arthur

Almost. Except, in real life, it is vice versa: First, we have the
perspective, and then we decide to represent the data in a list.

If I create different classes, with foreknowledge that instances will
serve some homogenous purpose in a list, I am nonetheless as
interested in what distinguishes those classes as I am in that
homogenous purpose. Otherwise they would be the same class.
And I am not unifluenced in my conceptualiztion by the knowledge that
those differences would, in programming languages much more widely
used than Python, be considered signifcant enough to disqualify their
co-existence (without further manipulation) in sequences that are
homogenous as defined by those languages.
People use the word "type" to mean different things. I try to use it
in what I consider the most generic sense, the one that is also
defined in ISO Open Distributed Processing:

"A type is a predicate"

In that definition "is green" is as much a type as "has used Python
to write software". In that sense, things in a list should share the
same type.

Other people use "type" to mean "class", but, in ODP terminology,
a class is a template: it can be used to create objects. Those
objects all share the same type, namely "is an instance of the
class". So, while classes do imply types, two objects that are
not instances of the same class may still have a same type.

I had made the point earlier in the discussion that I found it easier
to conceptualize something vaguely along these lines with old style
classes than with the new. Mr. Lundh assured me I was talking
nonsense, but since I was talking about intuitive conceptualization,
as a user, and Fredrik seemed to be coming me at me on some technical
grounds, I rejected the characterization.

[Or else he was deadon right, but tends to express himself in a way I
take as a form of bullying. Fredrik knows that he knows a lot more
about these issues than someone like myself, and if he is interested
in correcting a misconcpetion there are ways to do it, and ways to do
it.]

Newer Python seems to conform more to standard OOP, in concept. That
might not be true under the covers, but that is what we see. And I
think, therefore, there is a general expectation (or at least, I
don't think I'm alone in expecting) that it would conform relatively
closely to standard OOP in terminology.

I certainly have no problem seeing that expectation modified.

But until it is, it would be realistic to expect that - without
further explanation provided (and you are providing it) - that words
will be understood in there most commonly used sense.

Ar
 
A

Arthur

nonsense. Python has always used duck typing (what's important is what
you can do with x, not what type(x) happens to be). this hasn't changed a
bit.

Putting together what you and Martin are saying, am I correct then
that what type(x) returns in Python is something other than x's type.

that's strange.

Art
 
D

Donn Cave

Quoth Arthur <[email protected]>:
| On Tue, 25 May 2004 08:19:49 +0200, "Fredrik Lundh"
....
|> nonsense. Python has always used duck typing (what's important is what
|> you can do with x, not what type(x) happens to be). this hasn't changed a
|> bit.
|
| Putting together what you and Martin are saying, am I correct then
| that what type(x) returns in Python is something other than x's type.

Python's typing isn't all about what type(x) returns.

Donn Cave, (e-mail address removed)
 
A

Arthur

Quoth Arthur <[email protected]>:
| On Tue, 25 May 2004 08:19:49 +0200, "Fredrik Lundh"
...
|> nonsense. Python has always used duck typing (what's important is what
|> you can do with x, not what type(x) happens to be). this hasn't changed a
|> bit.
|
| Putting together what you and Martin are saying, am I correct then
| that what type(x) returns in Python is something other than x's type.

Python's typing isn't all about what type(x) returns.

And they tell me Python's great for kids ;)

Art
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Arthur said:
And they tell me Python's great for kids ;)

Indeed. Kids have real problems grasping the notion of types
(let alone of type hierarchies); I can tell from experience
that first-year computer science students still have these
problems.

With duck typing, the need to even introduce the notion of
types goes away: you invoke operation on objects, and if the
operation makes sense for the object, it will proceed. At
that point, it is irrelevant what other objects would also
allow the operation to proceed.

After a few months of Java, students are spoiled, and
consider static types and type hierarchies a natural thing,
and consider duck typing as evil.

Regards,
Martin
 
A

Arthur

With duck typing, the need to even introduce the notion of
types goes away: you invoke operation on objects, and if the
operation makes sense for the object, it will proceed. At
that point, it is irrelevant what other objects would also
allow the operation to proceed.

So I am not unjustified in a position that in not understanding typing
in Python, I am understanding it fine.

which is exactly what my intuition has told me.

Art
 
N

nnes

Arthur said:
"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!
 
A

Arthur

"A type is a predicate"

In that definition "is green" is as much a type as "has used Python
to write software". In that sense, things in a list should share the
same type.

I am as sorry as anyone else that I find this subject as interesting
as I do.

"Is green" doesn't help us if the list does not cohere around the
concept of color.

And the above sentences implies, and I could independently imagine, a
list might cohere around nothing more then the concept of existence.
But of course the possbility of including non-exitence data does not
exist. Which makes the notion of homogeneity around that concept
meaningless.

So I have, after consideration, decided to outlaw, if not the
terminolkgy itself (even its its most general form), than at least my
own efforts to find meaning in it.

Art
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Arthur said:
"Is green" doesn't help us if the list does not cohere around the
concept of color.

Correct. Any kind of predicate involving functions requires that
a certain base domain is used on which these functions are total.
And the above sentences implies, and I could independently imagine, a
list might cohere around nothing more then the concept of existence.

Correct. Of course, people typically collect things in a collection to
have algorithms operate on the elements of a collection, so a collection
of all things that exist would not be useful, and would be difficult to
create.
But of course the possbility of including non-exitence data does not
exist. Which makes the notion of homogeneity around that concept
meaningless.
Indeed.

So I have, after consideration, decided to outlaw, if not the
terminolkgy itself (even its its most general form), than at least my
own efforts to find meaning in it.

You find the term "color" meaningless because there are things it
doesn't apply to? Is there any term in the universe (or, perhaps
even in the English language) that you find meaningful?

Regards,
Martin
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top