[Python-3000] Iterators for dict keys, values, and items == annoying :)
Alex Martelli
aleaxit at gmail.com
Fri Mar 31 05:22:03 CEST 2006
On Mar 30, 2006, at 5:53 PM, Greg Ewing wrote:
...
>> Generally speaking I've remained suspicious of adaptation.
>
> I think to most people it seems like a solution
> looking for a problem. In all the code I've ever
> written, plain duck typing has been perfectly
> adequate. I'm willing to concede that it might
> have use in some specialised areas such as Zope,
> but there doesn't seem to be any general demand
> for it.
I concede that the peasants haven't (yet!-) stormed Guido's castle
with pitchforks and torches to get him to approve PEP 246, but I view
that as me not having done a good job of communication. Each and
every time a new ad-hoc-adaptation gets into the language (e.g., most
recently the __index__ one), I'm tempted to point out how much better
life would be with adaptation... but these days I mostly shrug and
get on with my life instead.
Consider __index__, and a user of gmpy, assuming gmpy didn't rush out
a 2.5 release with tp_index support. The user of gmpy would be stuck
-- no way he could use a gmpy.mpz as an index into a list, because
the ad-hoc-adaptation of __index__ means that the type itself must
grow the slot. _IF_ adaptation existed, a third party could write an
adapter from gmpy.mpz to indextype (or whatever), without needing any
tweak on gmpy itself NOR list objects' sources, and everybody else
could just import and use that adapter to make gmpy.mpz instances
usable as indices in the natural way.
And that's just for somebody using one humble library -- adaptation
really shines when you're using independently developed frameworks.
If the framework consuming X requested adaptation-to-X on all objects
it's passed, rather than checking them for this or that ad-hoc
protocol, as longs as a suitable adapter is registered the framework
producing Y's and the one consuming X's would just fit with each
other with no effort required on the part of the longsuffering
application developer.
I don't know why this shines so bright, so OBVIOUS, to me, and yet
I'm unable to convince Guido _or_ build a groundswell of support.
It's not as if I've done more multi-framework development than
anybody else, after all... just my share.
I guess I'll be back to campaigning for it more actively in the
future, once the Nutshell's 2nd edition is out. I'm seriously
convinced that having protocol-adaptation is the ONE change that
would make most positive difference to typical app developers today...
Alex
More information about the Python-3000
mailing list