Chapter 8

Namespaces, Packages and Modules

The namespace and package commands implement two different concepts that work together to make it easier to write reusable, modular, easily maintained code. The namespace command provides encapsulation support for developing modular code. The package command and modules provide tools for organizing collections of code into libraries.

The namespace command collects persistent data and procedure names in a private scope where they will not interact with other data or procedure names. This lets you load new procedures without cluttering the global space (avoiding name collisions) and protects private data from unintentional corruption.

The package command groups a set of procedures that may be in separate ...

Get Tcl/Tk, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.