[portland] Seeking opinions on choosing data types: dictionary or instance attributes?

Nick Welch mack at incise.org
Wed Nov 28 06:19:20 CET 2007


On Tue, Nov 27, 2007 at 01:44:53PM -0800, Adam Lowry wrote:
> First off, I'd suggest not making the class itself a dict (that is,  
> inheriting from UserDict).

Isn't UserDict pretty much a relic now, since new-style classes came
around and let us inherit directly from dict?

On the original topic -- I've personally turned against abusing classes
(or __getattr__) simply for the .foo.bar syntax.  Dict key access may be
a little more punctuationey, but it reminds you that you're dealing with
just a plain ol' dictionary, and that always feels nice to me.  If your
classes are only there to contain some keys and values (and don't have
any methods), then I feel that they fall into the category of needless
syntactic sugar.  If you just need a dict, then.. just use a dict!

-- 
Nick Welch | mack @ incise.org | http://incise.org


More information about the Portland mailing list