Namespaces and Modules
Team LiB
Previous Section Next Section

Namespaces and Modules

Systems have sub-systems and sub-systems have sub-systems and so on ad infinitumwhich is why we're always starting over.

Alan Perlis

The namespace is an important tool for managing names and reducing name collisions. So is a module, which is additionally an important tool for managing releases and versioning. We define a module as any cohesive unit of release (see Item 5) maintained by the same person or team; typically, a module is also consistently compiled with the same compiler and switch settings. Modules exist at many levels of granularity that range widely in size; a module can be as small as a single object file that delivers a single class, to a single shared or dynamic library generated from multiple source files whose contents form a subsystem inside a larger application or are released independently, to as large as a huge library composed of many smaller modules (e.g., shared libraries, DLLs, or other libraries) and containing thousands of types. Even though such entities as shared libraries and dynamic libraries are not mentioned directly in the C++ Standard, C++ programmers routinely build and use libraries, and good modularization is a fundamental part of successful dependency management (see for example Item 11).

It's hard to imagine a program of any significant size that doesn't use both namespaces and modules. In this section, we cover basic guidelines on using these two related management and bundling tools with a view to how they interact well or badly with the rest of the C++ language and run-time environment. These rules and guidelines show how to maximize the "well" and avoid the "badly."

Our vote for the most valuable Item in this section goes to Item 58: Keep types and functions in separate namespaces unless they're specifically intended to work together.


    Team LiB
    Previous Section Next Section