Concept
Modules And Namespacing
Modules and namespaces organize code into named boundaries for visibility, reuse, dependency management, documentation, and collision avoidance.
Related languages
What Modules Do
Modules create named boundaries. They help code declare what it exposes, what it imports, where names live, and how source files relate to packages, libraries, or deployable units.
The vocabulary changes by language. Rust has packages, crates, modules, and paths. Go has packages inside modules. Python has modules and packages tied to files and directories. Java has packages and, since Java 9, modules. JavaScript has ECMAScript modules plus host-specific resolution rules.
Why It Matters
Good module boundaries make large codebases reviewable. They reduce name collisions, keep internal implementation details private, document dependency direction, and give build tools something to compile, test, package, and publish.
Bad module boundaries create circular dependencies, unstable internal APIs, imports with side effects, hidden initialization order, and code that is hard to split or reuse.
Watch Points
Ask whether module paths are stable public API, whether file layout maps directly to namespace layout, whether package managers use the same unit as the compiler, and whether imports can run code at load time.
For libraries, treat exported names as durable. For applications, keep internal modules small enough that ownership is clear.
Related Concepts
Modules connect Package Managers, Build Systems, Documentation Cultures, and Object-Oriented Programming.
Sources
Last verified:
- Python Tutorial - Modules Python Software Foundation
- The Rust Programming Language - Packages, Crates, and Modules Rust Project
- How to Write Go Code Go Project
- Java Language Specification - Packages and Modules Oracle
- JavaScript modules MDN Web Docs