[Python-Dev] range objects in 3.x

Guido van Rossum guido at python.org
Tue Sep 27 03:44:07 CEST 2011


On Mon, Sep 26, 2011 at 6:25 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> While continuity of API might be a good thing, we shouldn't accept a poor
> API just for the sake of continuity. I have some criticisms of the linspace
> API.
[...]

> * I'm not sure that start/end/count is a better API than start/step/count.

On this particular one, I think start/end/count *is* better, because
in the most common use case the start and end points are given, and
the step is somewhat of an afterthought (e.g. how many integration
steps, or how many points in the chart). I also keep thinking that
numerically, if start and end are given exactly, we should be able to
compute the intermediate points within 0.5ULP, whereas it would seem
that given start and step our computation for end may be considerably
off, if the count is high. Or, maybe what I'm trying to say is, if the
user has start/end/count but the API wants start/step/count, after
computing step = (end-start) / count, the value of start + count*step
might not quite equal to end; whereas if the user has start/step/count
but the API wants start/end/count I think there's nothing wrong with
computing end = start + step*count.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list