On Jul 16, 2012 1:52 PM, "Stephen J. Turnbull" <step...@xemacs.org> wrote:
> The point is that I don't really see the value in returning a precise
> estimate that cannot be relied on to be accurate.  OK, Python is a
> "consenting adults" language, but returning an integer here seems like
> invitation to abuse.

Because preallocating memory is ridiculously faster than doing multiple
resizes. That's all this API is for: how many objects should a container
constructor preallocate space for when building from an iterable. It's an
important optimisation in CPython when using itertools, and PyPy is
planning to adopt it as well. Alex is doing the right thing in attempting
to standardise it rather than risk the two implementations using subtly
incompatible definitions.

Skipping the iteration in the zero case is a pointless micro-optimisation
that just makes the API more complex for no good reason. Allowing a
negative hint to mean "infinite", on the other hand, avoids certain
categories of errors without making the API any harder to use (since
negatives have to be rejected anyway).

--
Sent from my phone, thus the relative brevity :)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to