[swift-build-dev] [swift-dev] Right list?
Joe Groff
jgroff at apple.com
Fri Feb 26 12:40:27 CST 2016
> On Feb 26, 2016, at 10:30 AM, Max Howell <max.howell at apple.com> wrote:
>
>> 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.
Usernames strike me as too short to serve as a universal discriminator by themselves, and as you noted, tie the system to a specific service. Reverse-domain is certainly more precedented. I'm jumping into this conversation in the middle, so pardon me if this has already been discussed, but could the package manifest take responsibility for mapping global package identifiers to their source-level module names? That would let you say:
let dependencies = [
"SadunString": "org.sadun.SwiftString",
"FoobarStrings": "com.foobar.SwiftString"
]
and would give users some leeway to change their module references, should their dependencies end up forked or vendored.
-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-build-dev/attachments/20160226/9c69e728/attachment.html>
More information about the swift-build-dev
mailing list