[swift-build-dev] [swift-dev] Right list?
max.howell at apple.com
Fri Feb 26 12:30:59 CST 2016
> I first brought this topic up on swift-dev, and was pointed to swift-build-dev.
> Having spent considerable time messing up my Swift packages by giving them ridiculously obvious names like SwiftString and SwiftCollections, I realized that namespacing would be a solution for disambiguating conflicts. import SwiftString is insufficient when several packages are named SwiftString.
> When you have two identically named packages, the module imports need to distinguish both the sources as well as references defined per package. Although SwiftPM finds packages using git URLs and module names, I do not believe that origin is addressable or usable. Plus, throughout the lifetime of a package, that origin could potentially move from, for example, GitHub to Bitbucket.
> I suggest using some kind of origin key for differentiation. The simplest solutions for these include reverse domain names (basically a company/source identifier), git URLs (the current location of the repo), Github/Bitbucket user names (which are similar to a company/source identifier but more subject to updates over time).
> Of these, I’d recommend reverse domain for the following reasons:
> They are relatively short
> They are already well established for Apple app distribution
> They do not rely on a web address that may change should the repo move
> They are less likely to conflict with user names across repo hosts
> I’d imagine a package declaration that looks something like this:
> import PackageDescription
> let package = Package(
> name: "SwiftString"
> origin: "org.sadun"
> In the case of name conflicts instead of importing SwiftString, you’d prefix an origin:
> import org.sadun.SwiftString
> import com.foobar.SwiftString
> Ideally, you could further alias these to shorten symbol disambiguation:
> import org.sadun.SwiftString as SadunStrings
> import com.foobar.SwiftString as FoobarStrings
> // Unique to only one package, no name conflict
> uniqueMethod("Hello World")
> // name collision disambiguation
> SadunStrings.sharedMethod("Hello World")
> I'm interested in hearing any feedback and thoughts about whether this is possible and what I could do to help further this idea.
I think you have the right approach for sure. We need to talk with Swift-core as this will require work in that arena and they will need to chime in.
Certainly I would like to encourage namespacing with GitHub usernames because:
1) The majority of iOS open source happens there nowadays
2) People think of eg. mxcl’s PromiseKit, and thus both `import mxcl.PromiseKit` is very clear and communicates that these projects have origins/owners/maintainers.
However certainly I wouldn’t advocate for a GitHub only namespacing system, I just like that it have some extra sugar. SwiftPM was deliberately designed to be distributed.
I’ve cc’d Joe Groff since he probably can say something, then I can have some meetings, or we can try to do it all on the lists and then get this proposal written up.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-build-dev