[Python-3000] Builtin iterator type

Mike Orr sluggoster at gmail.com
Sun Nov 19 19:28:42 CET 2006


On 11/18/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> George Sakkis wrote:
>
> > The end user may not have to explicitly test for it, but it happens
> > anyway behind the scenes; x.foo is functionally equivalent to
> > if hasattr(x,'foo'): return getattr(x,'foo')
> > else: raise AttributeError()
>
> Well, yes, but the point is that since this is being
> done automatically anyway, doing it yourself as
> well is redundant.

*Something* is being done automatically but it's not the same thing.
The error message may be so unrelated to the actual problem as to give
no clue what's wrong.   Good code should reflect one's mental model,
as close to "one line per step" as feasable. If the language can have
features to facilitate this, why not? Many Pythoneers find interfaces
useful, or would if the language had them.  Making a concrete class
with dummy methods is kind of pointless when it'll never be used for
anything except isinstance(), and it's even worse at enforcing
attribute existence.  ("Yippee, I have a default attribute that's
None.")

There have long been discussions about adding interfaces and/or
adapters to Python, so it will probably happen someday. As has been
mentioned, Zope has had an interface implementation for years. PEPs
245 and 246 (both rejected) contain specific proposals for interfaces
and adapters. The last discussion I saw was in Guido's blog (April
2006):
http://www.artima.com/forums/flat.jsp?forum=106&thread=155123
There the discussion was on how generic functions could fulfill both
roles and more besides. The discussion seemed to fizzle out at, "Yes,
this would be nice to have," without a concrete proposal.

Simultaneously there was discussion on this list about it, although I
wasn't subscribed then so I haven't fully read it:
http://mail.python.org/pipermail/python-3000/2006-April/thread.html

-- 
Mike Orr <sluggoster at gmail.com>


More information about the Python-3000 mailing list