[ZODB-Dev] BTree.setdefault(), BTree.pop()

Christian Robottom Reis kiko at async.com.br
Tue Oct 5 10:55:04 EDT 2004


On Mon, Oct 04, 2004 at 02:42:08PM -0400, Jeremy Hylton wrote:
> On Mon, 4 Oct 2004 19:25:54 +0200, Dieter Maurer <dieter at handshake.de> wrote:
> > Tim Peters wrote at 2004-10-4 11:45 -0400:
> > > ...
> > >    pl = t.get(key)
> > >    if pl is None:
> > >        pl = t[key] = PersistentList()
> > >    pl.append(value)
> > >
> > >So I'm -0 on the idea, because I doubt it will be used.  I understand that
> > >you think you'll use it.  Anyone else?
> > 
> > I avoid "setdefault" almost always.
> 
> I've written some code using setdefault() recently, but I'm not
> satisfied with it.  There was a thread on python-dev several months
> ago where someone suggested a way to provide a factory for default
> values.  That seems like a cleaner API if you were going to add this
> feature.

+1; it's definitely the right way to do it. setdefault is both confusing
and wasteful in most cases I've seen IRL.

Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3361 2331


More information about the ZODB-Dev mailing list