Container __get/set/delitem__? (was Re: [Zope3-dev] naming is
sues: id vs name, delObject vs ?)
sean.upton@uniontrib.com
sean.upton@uniontrib.com
Tue, 14 May 2002 10:45:14 -0700
Until I've had my 3rd cup of coffee for the day, my fingers want to be lazy:
I really like the simplicity and brevity of folder['foo'] - personally, it
seems to me that while a container is not a mapping, in limited contexts it
has the ability at times to behave like one, so I like the idea of making a
container interface and extended version of a mapping.
Perhaps shifting the burden for clarity of "what an object is" to the
application coder to use well named identifiers eliminates most confusion: I
would have a pretty good hunch when reading someone else's code that
myFolder['foo'] and myLookupTable['foo'] are quite likely to be different
things despite their similarity in usage.
Sean
-----Original Message-----
From: Jim Fulton [mailto:jim@zope.com]
Sent: Tuesday, May 14, 2002 10:19 AM
To: R. David Murray
Cc: zope3-dev@zope.org
Subject: Container __get/set/delitem__? (was Re: [Zope3-dev] naming
issues: id vs name, delObject vs ?)
"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
_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
http://lists.zope.org/mailman/listinfo/zope3-dev