Forum OpenACS Development: Initializing Namespaces

Collapse
Posted by Kevin Crosbie on
Hi all,

I just wanted to post this as an idea for what I see as a good practice.

I'm writing a package, and have decided to put everything into it's own namespace, i.e, a namespace for the overall package, and a separate child namespace for each individual area of functionality.

e.g.
namespace eval package_name {}
namespace eval package_name::searching {}
namespace eval package_name::logging {}

However, the procedures which will be defined in each of these namespaces could be in different files in my tcl directory. Thus, I created a tcl library proc called 0-package_name-startup- procs.tcl which will create the hierarchy of namespaces on startup.

Then, inside each of the other procs files in the tcl folder, I define my procedures under the appropriate namespace.

The package_name namespace gets all of my global procedures The package_name::searching namespace gets all of my procedures associated with searching.

Thus, I can put my code into any tcl file I want, yet still maintain the overall grouping of methods.

The idea behind using namespaces like this is, first of all, to keep all of my procedures for my package separate to avoid collisions with other peoples packages, and second, to keep with the whole Object Model design. By using this structure, I can identify areas of functionality, and keep them together using a namespace. This keeps the general idea of the object more cohesive and re-usable.

The template namespace uses this idea in a big way and this is a standard that I am thinking of adopting when coding my own packages.

Any comments?

Cheers,

Kevin