[Python-3000] range() issues
Guido van Rossum
guido at python.org
Thu May 1 01:41:22 CEST 2008
On Wed, Apr 30, 2008 at 4:14 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>
> >
> > On Wed, Apr 30, 2008 at 3:49 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
> wrote:
> >
> >
> >
> > > So that code will silently behave as though the rest of
> > > the sequence wasn't there some of the time?
> > >
> >
> > Only if it uses LBYL.
> >
>
> I don't understand that. Iteration isn't the only thing
> one does with sequences. If you have a reason to call
> len() in the first place, I don't see how having it
> sometimes return inaccurate results can be helpful.
I've come across situations where len() raising an exception was more
inconvenient than returning a truncated value (e.g. when printing).
> > > Can you elaborate on the rationale for this?
> > >
> >
>
>
> > Ask the designers of the Java collections package.
> >
>
> Do you mean that they have a rationale which you agree
> with and think applies to Python as well, or do you
> mean that you're doing it just because Java does it
> and they must have a good reason?
>
> If the former, can you refer me to a document which
> espouses it?
You'll have to do some research, but I believe the circumstances are
similar -- they have a size() method that is defined to return an
unboxed int, so they are limited by that.
I found the spec here:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collection.html#size()
But I didn't find a rationale. I'm sure it was PBP though.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list