A Standard

Erik Max Francis max at alcyone.com
Sun May 25 20:49:09 EDT 2003


Andrew Koenig wrote:

> STL incorporates an important idea that Python is only just beginning
> to
> adopt, namely that of imposing an abstraction layer between containers
> and the programs that deal with them.

It seems to me that such abstraction layers are already inherent in
Python, due to Python's dynamicism.  The documentation talks about
"sequence types" and "mapping types," acknowledging full well that these
describe _interfaces_ that non-builtin types can emulate and replace
builtin types whenever a sequence object, rather than a specific type
(e.g., tuple or list), is required.

To implement an object that implements the sequence interface, just
create a class that has a __getitem__ method which returns meaningful
values for 0 .. n - 1, and thereafter returns IndexError (there are of
course further elaborations on the interface which can be used, which
will).

The only qualitivative difference I can see between STL-like container
interfaces and Python's high-level type interfaces is that container
interfaces seem more "unified," but even that isn't quite true, e.g.,
the duplicate usage of __getitem__ in sequence and mapping types in
Python.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Laws are silent in time of war.
\__/  Cicero




More information about the Python-list mailing list