Counterintuitive Python behavior

Steve Holden sholden at holdenweb.com
Mon Apr 22 08:56:12 EDT 2002


"Greg Weeks" <weeks at vitus.scs.agilent.com> rode in on his hobbyhorse to
assert...
> Some comments regarding "conceptual sameness":
>
>
> From: "Petr Prikryl" <Answer.via.news.please.prikryl at skil.nospam.cz>
>
> > There are two distinct things when comparing the objects: the object
> > content and the object identity.
>
> Neither of these concepts corresponds to conceptual sameness.  I haven't
> defined "conceptual sameness", but it is a natural concept:
>
If it's a natural concept then a definition shouldn't be too hard. Come on,
you can do it.

[spurious examples]
>
> Are these the same string?  Conceptually, yes.  When you are comparing
> strings in your code, it will be conceptual sameness that you are
> interested in.  But neither the identity nor the content of s1 and s2 are
> the same.
>
> So, conceptual sameness corresponds sometimes to sameness of identity,
> sometimes to sameness of content, and sometimes to neither.  And (I
> maintain), in ordinary user code, conceptual sameness is the concept of
> *identity* that is most useful.  (I stress "identity" because there are
> weaker forms of comparison that are sometimes useful.  But not *as*
> useful.)
>
Well, if you wave your hands long enough you might persuade some readers
that this all *means* something. But I'm not convinced you are yet at the
stage where you could provide a patch to add a "conceptual sameness"
operator to the language. Clearly object identity and object equality
*might* be equivalent for some types/classes.

At present Python, with its typically pragmatic approach to these matters,
does not insist on single-copy instances for immutable types. Consequently
it is possible for a == b to be true even though a is not b.

> So Python is missing THE single most useful comparision operator.  But
> there are workarounds.  "==" means conceptual sameness for all objects
> other than lists and dictionaries, provided that __cmp__ is appropriately
> defined.  Furthermore, if __hash__ is appropriately defined, any objec
> other than a list or dictionary can be a hash key.  So, except for lists
> and dictionaries, everything's fine.
>
I don't feel you have yet even adequately *defined* "conceptual sameness",
so it's surely premature to assert that it's missing from the language.

regards
 Steve
--

home: http://www.holdenweb.com/    book: http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list