Namespaces × submodules

Here’s how I see things:

• A submodule is not a module. In particular, un-annotated declarations are implicitly internal, and thus visible to the entire module, regardless of which (if any) submodule they are in. There needs to be a separate keyword for “visible in this submodule only”, and I recommend we find one that can completely replace fileprivate, using the rationale that a file is inherently its own submodule unless specifically made part of another submodule.

• A submodule is not the same as a namespace. Namespaces are a separate concept, similar to an empty enum. A single file can be used for multiple namespaces, and a single namespace can be used in multiple files. By contrast, a submodule is specifically used for grouping related files.

• If a submodule behaves like a namespace, it should be a “transparent” namespace, meaning that its name *does not* need to be provided when accessing things inside it (except when necessary for disambiguation).

• Submodules cannot be nested. A module can contain submodules, and a submodule can contain files, and that is that.

• • •

Thus, a submodules is primarily an organizational tool, providing a level of access control intermediate between “one file” and “the whole module”. Anything inside the submodule can be accessed directly, without writing the submodule name, from anywhere that it is visible.

1 Like