[Zope3-dev] PyCon DC 2003: Call For Papers
Shane Hathaway
shane@zope.com
Thu, 05 Dec 2002 10:37:53 -0500
Stephan Richter wrote:
> On Thursday 05 December 2002 08:41, Guido van Rossum wrote:
>
>>- Module and package names should be short and lowercase. Motivation:
>> you'll never again confuse a class with its module.
>
>
> I like that.
>
>
>>- Modules should contain more than one class (a rule designed to be
>> broken :-). Motivation: this way the presentation order of classes
>> (whether top-down or bottom-up) can help the reader to understand
>> what's important; and it clarifies what classes (or functions) are
>> related. Compare to trying to find where to start in a directory
>> full of classes, listed alphabetically.
>
>
> That has another advantage: You do not have to write the name twice in the
> import. Right now we often have: from package.ClassName import ClassName
I've been trying out a complementary convention in AdaptableStorage: all
public classes are available through a special module called "public".
For example, if I made a class JobBoard and put it in jobboard.py,
located in the package "jobboard", I'd put a public.py next to it that
includes the line "from jobboard import JobBoard". Other packages would
use this class with the statement "from jobboard.public import
JobBoard". There are many advantages:
- The public.py module becomes the documentation for use of the package
by other packages.
- The class name does not get repeated when other packages use the class.
- You can convert any package to this convention just by adding a
"public" module. It conflicts with no other conventions (unless
"public" ever becomes a Python keyword ;-) )
- It's a lot like Java imports, but without the warts. Hence I think it
is likely to help those coming from Java, as I did. In Java you would say:
import jobboard.JobBoard;
In Python you would say:
from jobboard.public import JobBoard
... which are essentially equivalent and easy to translate. But what if
you want to import a lot of classes from another Package? Java:
import jobboard.JobBoard;
import jobboard.HTMLJobBoardRenderer;
import jobboard.XMLRPCJobBoardRenderer;
In Python you can shorten this to:
from jobboard.public import JobBoard, HTMLJobBoardRenderer,\
XMLRPCJobBoardRenderer
- As just illustrated, you can more easily import multiple classes from
a package. You don't need multiple "import jobboard.xxx" statements.
- Other packages can still choose to ignore the convention and get the
classes directly.
Shane