Namespaces × submodules

My 2c on this:

Syntactically, we should have a definition of a namespace, like this:

namespace Foo {}

and given that it should probably have braces, it should allow things to be defined inside of it explicitly. However, I agree we don't want to have entire files nested under namespaces. Something file-based like Java's package system is one very reasonable approach on this: a definition in the file specifies the default namespace for everything within it.

Another (complementary) approach we could consider is to allow defining declarations explicitly in namespaces, e.g.:

struct Foo.MyStruct {
}

Semantically, I think it is really important to think about the role and behavior of submodules, and whether we really want something like namespaces, or something more highly developed like a submodule. We already have the ability to import submodules from ObjC modules (e.g import Foundation.NSArray) but it is not fully baked out and not developed with Swift submodules in mind.

It is important to understand that space before tackling something like this.

-Chris

10 Likes