module not callable - why not?

Hung Jung Lu hungjunglu at yahoo.com
Sun Apr 18 12:23:33 EDT 2004


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote in message news:<7xsmf1fxd9.fsf at ruckus.brouhaha.com>...
> Josiah Carlson <jcarlson at uci.edu> writes:
> > I think of modules as a namespace.  Why?  Because that is what they
> > are. They contain a space of names, some of which may be useful to
> > you, otherwise you wouldn't have imported the module.
> 
> Is a class instance not also a namespace?  After all, it contains a
> space of names, some of which you must have wanted or else you
> wouldn't have instantiated it.
> 
> And yet, you can call a class instance if it has a __call__ operation
> defined.  I don't see why modules shouldn't be the same.

Exactly. Another thing people have complained about is the lack of
getters/setters for module properties. For classes, you can have
properties. For modules, you can't.

Look, here is a partial list of the symptoms of the illness of using
class-and-module-based OOP:

(a) You need metaclasses. You have special syntax for usage of
metaclasses: you need to use the __metaclass__ name tag, in specific
places.

(b) Singletons become a "design pattern", since classes usually cannot
be used as instances directly.

(c) You have to create staticmethod and/or classmethod to make a class
functional.

(d) Modules can't have properties, nor are callable.

(e) You often need to create three objects: module, class, instance,
to do the job of one single object. Hence you often see usage of the
same name for all three of them, weird as it may seem.

(f) Module inheritance ('import' for containment, 'from ... import'
for inheritance) differs in syntax with class inheritance ('class
A(B):')

(g) Module functions and class methods become two distinct types of
objects.

In prototype-based OOP, you don't have any of these problems. You can
see that the usage of modules and classes introduces a whole lot of
repeated/redundant concepts and/or inconsistencies. That's the price
you pay. It's just an unfortunate historical development that lead us
to where we are today.

regards,

Hung Jung



More information about the Python-list mailing list