A Standard
Roy Smith
roy at panix.com
Sun May 25 20:38:45 EDT 2003
Luis Cortes wrote:
>> porting the STL library from C++ completely re-written in python.
Sean 'Shaleh' Perry <shalehperry at attbi.com> wrote:
> When you move to a new language it is important to learn how that language
> works.
That's an excellent point.
I'm in the process of quasi-porting a library from TCL to C++/STL. We
want to preserve the flavor of the API, but at the same time, end up
with something that a C++ programmer can feel comfortable/familar with.
To do that, there's a certain amount of "letting go" that's required.
Exactly how much is a matter of some debate :-)
It's kind of like translating poetry to another language. So much of
poetry and literature is language-specific, what works in one language
may not work in another. The translator needs to find a way to capture
the essense of the verse without getting bogged down in technical
details. Shakespeare wrote in iambic pentameter. Does that mean
somebody translating Hamlet into German or Chinese or Arabic should
force the result to be iambic pentameter as well, regardless of how well
or poorly the host language supports it?
STL is a very C++ specific thing. Python has iterators, but they're a
somewhat different beast from STL's plethora of iterator types
(specifically, the idea of begin/end iterator pairs makes no sense in
Python's model). std::string is entirely superfluous given Python's
built-in string type. Much of STL has to do with const correctness,
which has no parallel in Python.
The big thing, however, is that STL is an impressive effort to implement
data-type independant programming in a language which is extremely
sensitive to data types. Such a thing makes no sense in a dynamic typed
language like Python; it's like trying to sell ice to Eskimos.
The containers themselves are mostly subsumed by Python's own container
types. There's not much you can do in STL containers that doesn't
translate directly into some combination of dicts, lists, and tuples.
More information about the Python-list
mailing list