[Python-3000] Builtin iterator type

Bill Janssen janssen at parc.com
Fri Nov 17 20:22:58 CET 2006


Greg Ewing wrote:
> George Sakkis wrote:
> 
> > And for two, not everyone feels comfortable with duck typing. People
> > who consider (for better or for worse) isinstance() safer than
> > hasattr()/getattr() would be accomodated too.
> 
> The trouble is that building things into the core to
> "accommodate" these people ends up making things worse
> for people who don't subscribe to that school of
> thought, because they will trip over places where
> some type won't be acceptable because it doesn't
> inherit from the right bases, even though it
> implements all the functionality required for their
> application.

I think that the issue is whether the caller can know whether their
type "implements all the functionality required for their
application".  If the library function they are calling is effectively
opaque, they somehow have to understand all the checking logic that
that function will perform, to build their type and pass their
parameters effectively.  The use of standard base types (interfaces)
is basically a communications mechanism that lets functionality
designers easily tell users of their functionality what's needed.

Using isinstance() instead of hasattr()/getattr() allows for more and
better communication, too.  Checking for some textual attributes of a
type can't capture semantics not expressed in those textual
attributes, which a "type" can capture that kind of intangible
attribute.  Finally, checking for one type instead of a vast variety
of possible syntactic checks is probably usually more efficient, as
well.

> I would suggest that if someone is that uncomfortable
> with duck typing, then perhaps Python is not the
> right language for them.

Wow.  I think that lots of folks aren't exactly uncomfortable with it.
It's more that they see it as a blemish on what's otherwise a pretty
good language, and what's more, they see it as an unnecessary blemish,
since Python's type system is (and this is a rarity among languages)
powerful and flexible enough not to *need* duck typing.  They
contribute suggestions about how to remove the necessity for it in a
spirit of public service, to improve the commonweal by improving
Python, to improve your life and the lives of all Python users.  Much
like your work on PyGUI.  And the suggestions I've seen aren't about
making it *impossible* to do duck typing in Python, but rather about
making it *unnecessary* to do duck typing in Python.

Bill


More information about the Python-3000 mailing list