[Python-Dev] defaultdict proposal round three

Alex Martelli aleaxit at gmail.com
Wed Feb 22 16:47:33 CET 2006

On Feb 22, 2006, at 7:21 AM, Raymond Hettinger wrote:
> I'm somewhat happy with the patch as it stands now.  The only part  
> that needs serious rethinking is putting on_missing() in regular  
> dicts.  See my other email on that subject.

What if we named it _on_missing? Hook methods intended only to be  
overridden in subclasses are sometimes spelled that way, and it  
removes the need to teach about it to beginners -- it looks private  
so we don't explain it at that point.

My favorite example is Queue.Queue: I teach it (and in fact  
evangelize for it as the one sane way to do threading;-) in "Python  
101", *without* ever mentioning _get, _put etc -- THOSE I teach in  
"Patterns with Python" as the very bext example of the Gof4's classic  
"Template Method" design pattern. If dict had _on_missing I'd have  
another wonderful example to teach from!  (I believe the Library  
Reference avoids teaching about _get, _put etc, too, though I haven't  
checked it for a while).

TM is my favorite DP, so I'm biased in favor of Guido's design, and I  
think that by giving the hook method (not meant to be called, only  
overridden) a "private name" we're meeting enough of your and /F's  
concerns to let _on_missing remain. Its existence does simplify the  
implementation of defaultdict (and some other dict subclasses), and  
"if the implementation is easy to explain, it may be a good idea",  
after all;-)


More information about the Python-Dev mailing list