A Standard

Dave Benjamin ramen at lackingtalent.com
Fri May 30 13:55:30 EDT 2003


In article <yu99u1bgic1a.fsf at europa.research.att.com>, Andrew Koenig wrote:
> There is a key difference: A C++ forward iterator is a first-class
> value, which means that you can copy it and use it again later to
> iterate over the same sequence a second time.  In general, you can't
> do that with a Python iterator.  Moreover, you can modify the values
> of the elements of the sequence to which a forward iterator refers
> (unless the elements themselves are of a type the prevents
> modification).

This is an important distinction, I think. STL iterators are values. They
can be compared, stored, advanced, etc. Python's concept of an iterator is
single-pass and (usually) sequential. It's more like a stream.

I like Python's syntactical support for iterators, especially the ability to
transparently replace in-memory list iteration with lazy iteration without
changing the loop itself. However, there is a lot to STL that Python doesn't
do, and I don't think it's fair to simply write it off by saying the STL is
just a band-aid for the weaknesses of C++, and Python has better ways of
doing *everything* STL does.

I would be very interested to see how some of the ideas behind STL could
benefit Python, and I think that there is more to the concept of "generic
programming" than just dealing with the inflexibility of a static type system.

We should try to be more open-minded.

Peace,
Dave





More information about the Python-list mailing list