[Python-3000] Builtin iterator type

George Sakkis george.sakkis at gmail.com
Wed Nov 15 09:47:22 CET 2006


Fredrik Lundh <fredrik at pythonware.com> wrote:

> George Sakkis wrote:
>
> > I won't open another can of worms here, but I'll just say that as much
> > as I hate Java's stubborn insistence on OO purity, I am equally
> > disturbed by Python's arbitrary-looking choices on whether some
> > callable ends up a function or a method. When I talk about or
> > introduce Python to outsiders, one of the toughest questions is often
> > > something along the lines of "why len() is a function and not a
> > method?"
>
> I guess those outsiders don't really understand the concept of a
> "generic operation".  are you sure *you* understand what that is?
> it's not obvious from your your posts.

Perhaps I don't, but if you or anyone else wants to enlighten me, please make
sure you include in your explanation

1) why having a "generic operation" len() that ends up looking for an
ugly special *method* called  __len__() makes sense, while calling
directly a method len() doesn't, and

2) if "generic operations" are such a cool idea, why there aren't more
of them, such as count() or index() (the former for any container
type, the latter for sequence types).

I don't think that defending a decision by pointing out a different bad decision
in another language (Java's inconsistency between string.length and
list.length())
is a particularly compelling argument, especially in an FAQ page. The ending
sentences though are more convincing: "...but it's a part of Python,
and it's too
late to make such fundamental changes now. The functions have to remain to avoid
massive code breakage". That I can buy (at least for 2.x).

George


More information about the Python-3000 mailing list