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

Jim Fulton jim@zope.com
Tue, 14 May 2002 13:19:04 -0400


"R. David Murray" wrote:
> 
> In an IRC discussion Jim, SteveA, and I talked about some naming issues
> with the current code, and we would like more input.
...

> 2) delObject vs ?
> 

We had some additional discussion about whether IContainer should just use
__get/set/delitem__ (and keys, values, and items) to be more familiar. If 
you look at IContainer, it it defines methods that are exactly equivalent
to a number of typical mapping methods, but have "funny" (as Guido put it) 
names. I originally resisted this on the grounds that containers were
not equivalent to mapping objects.  Of course, it might be OK if containers
were mapping objects and more, or, in other words, if container interfaces
extended mapping interfaces.

So, to summarize, there's a proposal to rename some methods from
IContainer:

    old             new
    ------------    -------------------
    objectIds       keys
    objectValues    values
    objectItems     items
    getObject       __getitem__ and get
    hasObject       has_key
    objectCount     __len__
    setObject       __setitem__
    delObject       __delitem__

Pros:

  - More familiar. Less to remember.
  - folder['foo'] is more readable than folder.getObject('foo')

Cons:

  - The change may cause too much confusion between containers and 
    dictionaries or other mapping objects. Content containers are 
    not dictionaries. They have more specific semantics and shouldn't be

Alternate proposal:

  Provide an adapter (or family of adapters) from containers to mappings.

  Pros:

    - The adapter could create context wrappers, which would be nice.
      Currently, these get created by the traversal machinery. Context
      wrappers are needed to enable security to find grants when checks
      are done.  

  Cons:

    - The adapter would be a bit of a pain to use:

        getAdapter(folder, IMapping)['foo']

      Maybe we could think of some sort of shortcut:

        mapping(folder)['foo']

Jim

--
Jim Fulton           mailto:jim@zope.com       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org



--
Jim Fulton           mailto:jim@zope.com       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org