Implicit lists

Donn Cave donn at u.washington.edu
Mon Feb 3 12:38:40 EST 2003


Quoth Christian Tismer <tismer at tismer.com>:
...
| Python's flexibility is great. At the same time, it is
| its own enemy. I can have atomic objects, lists, tuples
| and general sequences, and I can pass them to functions
| which accept atoms, lists, tuples and sequences, but there is
| no way to tell the function whether I meant to pass something
| like an atomic object or like a sequence.
|
| Is the consequence to always try to avoid polymorphic interfaces,
| or do we need a new construct to express our intent?
| I could imagine an inquiry function that would yield such information,
| and in the case of strings, this would say "treat me as an atomic".

Do you think this is polymorphism, when a parameter may be either
an atom or a collection of same?  I don't.  Don't know what I'd
call it, maybe it doesn't deserve a name.

I've run into the problem, all right, but in my opinion it's more
of a symptom of sloppily engineered software that relies too much
on Python's introspection.  Some of that software is Python itself -
for example, if you try to handle exceptions somewhat generically
at the top level of an interactive application, I think you'll find
yourself trying to sniff out various object properties.  Maybe it's
an inevitable fact of life, and like I say I've sure brought it on
myself plenty of times, but it's also a losing game, and I wonder
if it's better to feel the pain of losing and be motivated towards
better defined interfaces.

	Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list