[Python-Dev] iterator API in Py3.0
annaraven at gmail.com
Sat Mar 4 18:34:50 CET 2006
On 3/3/06, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
> > * As a writer/teacher, I want to be able to say, "All Python special
> > methods have leading and trailing double-underscore." Period, end of
> > story.
> When teaching your classes, do you sense an aversion to using double
> methods in regular code? I sense an implied message that these methods
> are not
> intended to be called directly (i.e. the discomfort of typing
> serves as a cue to write x[k]=v instead; likewise, x.__int__() pushes
> int(x) instead).
> If so, then that is a good reason to leave it.next() as-is. Unlike
> or __int__, the next() method is intended to be called directly in normal
> Of course, for-loops are the most common case and it makes no difference
> however, in the rest of the cases where the iterator is accessed directly,
> current naming is clean, readable, and doesn't provide an aversive cue.
> The double underscore convention is appropriate where the method is always
> invoked magically in normal code and not called directly. The next()
> method is
> differenct because it is a mixed case, sometimes called magically and
> called directly. In the latter case, the name is highly visible and
> should not have double underscores.
> I suspect that those who feel differently are ones who usually avoid
> next() directly. That's okay, but we shouldn't muck-up the naming for the
> of us who often do have a need to use next().
> This is doubly important because we're now expanding the protocol to
> send() and throw(). Adding underscores around them too will only make
> methods look harder to use than they actually are. Don't underestimate
> psychological revulsion to calling code filled with piles of double
I think this is a really good point. next() is supposed to get used, by
coders, in regular code - so it shouldn't be __next__. I can understand the
desire for both forms, although that seems it would clutter things up
unnecessarily - particularly if the two do the same thing.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev