Refactoring Dilemma

Carl Banks pavlovevidence at gmail.com
Mon Sep 11 05:02:16 CEST 2006


George Sakkis wrote:
> I prefer the the simple global statements if they aren't
> that many, otherwise the assignment of the module to self is also fine.

I replied to this article, and then canceled the reply (but that never
works), thinking you were criticizing the general concept of "module as
a singleton" and not just my approach.  I should learn to read.  I
apologize for the misunderstanding.

I do agree my implementation is a little hacky, although IMHO it feels
to fit in with the way classes work better, which appeals to me but
probably not most people :).  For one thing, the methods have the
explicit self argument, like regular classes.  For another, it uses a
decorator to affect the binding of the modules.  In regular classes,
functions are instance methods by default, and become class methods or
static methods with a decorator.  I like to think of modules as having
a special metaclass that treats functions as static methods by default,
and uses a decorator to get an instance method.  (Even though that
isn't remotely how it works, it fits how it would work if you were
implementing modules based on classes.)

Having said that, I've no problem with Kamilche's approach.  The real
evil in my mind is using lots of global statements, and anything you
can do to stay away from that is a good thing.


Carl Banks




More information about the Python-list mailing list