The chapters so far have covered the basic elements of day-to-day Tcl programming, so-called ‘programming in the small’. In this chapter we now consider how to take a body of Tcl code and package it up so that it can be used and reused by others; ‘programming in the large’. There are a number of issues involved when making some code available for use by other developers, whether you are targetting a small number of colleagues, or making your code available for download by the general public.
Firstly, we wish to avoid name clashes. That is, if we have a procedure named do_something, then we want to ensure that this doesn’t interfere with any other procedure with the same name in a different package.
We will want to encapsulate our code into an integrated functional component, which is insulated from other code in the system. This is done to maintain a clear separation between the interface of our component, and it’s implementation. We then also want to ensure, as much as possible, that the assumptions made in that implementation are robust against accidental tampering.1
We can package our code so that it is easy to load into an existing Tcl application. We can also supply version information with our package, so that users can identify which revision they require.
In addition, there are other matters which are important to consider when distributing code to other users, such as writing clear documentation, implementing and using a unit and regression test suite, and setting up some means of support, such as a mailing list or forum. These considerations are largely non-Tcl specific, and so are not covered here. Use of the tcltest framework for unit testing is covered in Section 4.4.