[Zope-CMF] [dev] Re: shared mutable defaults

Tres Seaver tseaver@zope.com
06 Feb 2003 12:06:13 -0500

On Thu, 2003-02-06 at 03:46, Yuppie wrote:
> Hi!
> Tres Seaver wrote (regarding a cvs checkin for ActionProviderBase.py):
> >>-    _actions = ()
> >>+    _actions = []
> > 
> > 
> > Past experience has demonstrated quite painfully that shared mutable
> > defaults are evil, and a source of really hard-to-find bugs;  code which
> > works fine in unit tests, and when only one user is working on a system,
> > breaks mysteriously when multiple users / requests are firing.
> > 
> > Nobody should depend on this, so please revert it (the next part is
> > fine).  Any change you made which *does* depend on having the class
> > attribute be a list is, by definition, a bug waiting to be discovered.
> *All* subclasses of ActionProviderBase overwrite this default tuple with 
> a default list. I thought there is a reason for that, but it seems I was 
> wrong: '_actions' needs to be a sequence, not a list.
> Does that mean all action providers are broken and should be fixed?

Hmm, I think so.  I would say that making all those lists into tuples
should be a no-impact change, and it would make the inttent clearer.

Note that the one piece of code which does the Right Thing (TM) is the
CMFCore/TypesTool.py:  ironically, that code was slated to be ripped out
after 1.3, and replaced with an APB-derived TypeInformation class (in
CVS on the 'tseaver-typeinfo_as_apb-branch').  Perhaps we should work
out whether to merge that branch for 1.4?  I think the only downside is
that we would need to handle forward-compatibility for old type
information objects.

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