Container __get/set/delitem__? (was Re: [Zope3-dev] naming issues: id vs name, delObject vs ?)

Tres Seaver tseaver@zope.com
15 May 2002 09:59:19 -0400


On Wed, 2002-05-15 at 02:23, Barry A. Warsaw wrote:
> 
> >>>>> "KM" == Ken Manheimer <klm@zope.com> writes:
> 
>     KM> I may be weird (rhetorical device; raises a knowing smile in
>     KM> everyone:-), but i have *never* gotten over the dissonance of
>     KM> ".objectIds()" / ".objectValues()" / ".objectItems()", etc, on
>     KM> Zope2 folders.  They were mis-motivated.  Having similarly
>     KM> named methods helps those of us with feeble memories remember
>     KM> how to do similar things with diverse objects, *in so far as
>     KM> the objects are similar*.
> 
> Just to agree more <wink>, making Zope more "pythonic" means building
> a bridge from what you know to what you don't know.  This is also
> known as being habitable, or discoverable, etc.
> 
> The point is that our common language is Python, and where Zope is
> similar to, or builds on, Pythonic constructs, it too should spell
> things Pythonically.  Departures from that should probably be limited
> to situations where the differences are important enough that you'll
> get into trouble if you look too Pythonic but really aren't

You have identified what makes me uncomfortable about "all folderish
things are mappings":  in Zope, this assumption, used naively, can lead
to ugly scaling problems.  Of course, like all scaling problems, the
"naive" approach works fine in development;  it only blows up when the
actual number of objects in the container gets large.

Python's "mapping protocol" feels too loose for an interface-driven
system such as Zope3 to emulate properly:  we should layer the
interfaces (e.g., as the 'Interface.Common.Mapping' module does, only
more so).  Containers which permit '__getitem__/get' access to their
items should not likewise be required to allow 'keys/items/values'
(*especially 'items/values'!);  likewise, allowing '__setitem__' should
*not* promise that 'update/clear/etc' are available.

So, in the end, I would argue that the spelling::

   for key, item in getAdapter( folderish, IEnumerableMapping ).items():
       #...

if far superior to::

   for key, item in folderish.items():
       #...

because it doesn't assume "folder is just like dictionary";  instead, it
leverages the component architecture, so that an adapter for "expensive"
containers could be written which "lazified" the 'items' and 'values'
calls.

> e.g. (perhaps -- but it's late and I'm tired ;), "del obj['usr']" rm's
> your /usr directory.

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com