[Tutor] Larger program organization

Kent Johnson kent37 at tds.net
Sat Feb 12 17:28:45 CET 2005

Ryan Davis wrote:
> I'm starting to make a code-generation suite in python, customized to 
> the way we ASP.NET at my company, and I'm having some trouble finding a 
> good way to organize all the code.  I keep writing it, but it feels more 
> and more spaghetti-ish every day.

Organize your code into packages. Give each package a clear responsibility and clear dependencies on 
other packages. For example my current (Jython) project has these packages:

app - top-level application objects
data - database access - all the SQL code and database objects
dbload - helpers for initial database load
gui - gui classes
importer - classes to implement an import function
main - misc. main programs, not really part of the main app
server - embedded web server
tree - support for the Swing TreeModel that is a major part of the app
writer - generation of output files

I also use some packages that are not specific to the application:
db - generic database support
swing - generic Swing widgets and support classes
util - misc helpful stuff

In total there are 121 Python files (including test modules) and 49 Java files.

For a smaller project you might just have a few modules in one package, or just a couple of packages.


More information about the Tutor mailing list