[Python-ideas] Reversable

Paul Moore p.f.moore at gmail.com
Fri Apr 30 00:33:24 CEST 2010


On 29 April 2010 12:22, cool-RR <cool-rr at cool-rr.com> wrote:
> Yes, I'm aware the implementation is simple. I was not asking for an
> implementation. I was just raising the idea that it should be part of the
> builtin `reversed`. But since there are no +1s, I guess not.

Sorry. My point was that the gains (in terms of the difficulty of
implementing it yourself) are minor, so the cost doesn't justify it.
Specifically, the costs are (1) extra complexity when describing the
behaviour of reversed() and (2) more seriously, potential crashes if
an infinite generator (for example) is passed to reversed() in error.

Currently, reversed(infinite_gen) is a trappable error. With your
proposal, it would halt the program until all memory was consumed,
then crash. Anyone using a custom function such as my
reversed_anything can be assumed to understand its limitations,
whereas builtins can be assumed to behave "nicely".

Looking at it the other way, it's easy to build reversed_anything
given reversed, but it's not possible to build reversed given only
reversed_anything. The builtin function should be the one that can be
more easily used to build from.

My apologies for being too terse.
Paul.



More information about the Python-ideas mailing list