[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: packages, modules, etc...

Gary King <gwking@cs.umass.edu> wrote:
 >Even little languages end up with lots of named "things" and therefore 
 >need some way to organize them. I'd like to hear opinions and ideas 
 >about better organizational schemes than what currently exists.
 >To get things started, it's pretty common to hear complaints about 
 >Common Lisp's package system (for example, in 
 >http://www.norvig.com/python-lisp.html, Peter Norvig says that Python's 
 >module system is easy to use while CL's is hard to use). Now I have not 
 >done any Python programming but a quick look at the tutorial on Modules 
 >(http://www.python.org/doc/2.3.2/tut/node8.html) didn't convince me. Is 
 >Python's module / package system easier to use? Does CL's package 
 >system really suck?

Ok, so I haven't used Common Lisp's package system, but I rather like
Python's, which is almost frighteningly simple.  In Python, almost
everything is a dictionary, including the modules.  A file named
"foo.py" creates a module named "foo" when imported, containing the
classes, functions, variables, and what-not defined in the file foo.py.
Once imported, you can query the dictionary and insert, delete, or
modify anything in it.  You can also assign one of the module's objects
to a local identifier, which is roughly the semantics of "from module
import identifier".  Interactive development is handled by a "reload"
operation (Ok, so I can't remember whether it is a function or a
statement.  I don't use it very much because,) but it has problems with
local aliases to module contents.

One really nice thing is that the modules are first-class objects.  You
can assign the module to an identifier, which then becomes an alias for
the module.  The module can be passed around or treated almost like an
object with the module contents as attributes.  One trick that I haven't
seen elsewhere is to conditionally load one of a group of equivalent
modules and assign it to a local identifier, which then becomes usable
as a sub-module.

The package system is an extension of the module system, allowing
file system directory structure (plus some special files) to act as
hierarchical modules.

Tommy McGuire