<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 19, 2016, at 5:50 PM, Max Howell <<a href="mailto:max.howell@apple.com" class="">max.howell@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Yes, we should probably take this to swift-build-dev.<br class=""><br class=""><blockquote type="cite" class="">I'd like to add a Package property to namespace packages by origin,<br class=""></blockquote><br class="">Some namespacing will certainly be required, the sooner the better.<br class="">I was hoping to namespace with github username where possible, it’s mxcl’s PromiseKit after all.<br class=""><br class=""><blockquote type="cite" class="">and to add aliases in Swift for renaming imports.<br class=""></blockquote><br class="">With namespacing we probably wouldn’t need this solution, which would be more ideal, eg:<br class=""><br class=""> import Foo<br class=""><br class="">Now you have two Foo, so any package that uses both must be specific:<br class=""><br class=""> import mxcl.Foo<br class=""> import erica.Foo<br class=""><br class="">Provided they are compiled such that the build system knows the namespaces at all times, we should be good. It’s only the user who doesn’t need to know at all times.</div></div></blockquote></div><br class=""><div class="">Following up on this.</div><div class=""><br class=""></div><div class=""><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class=""><em class="">I first brought this topic up on swift-dev, and was pointed to swift-build-dev.</em></p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">Having spent considerable time messing up my Swift packages by giving them ridiculously obvious names like <code class="">SwiftString</code> and <code class="">SwiftCollections</code>, I realized that namespacing would be a solution for disambiguating conflicts. <code class="">import SwiftString</code> is insufficient when several packages are named <code class="">SwiftString</code>. </p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">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. </p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">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). </p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">Of these, I’d recommend reverse domain for the following reasons: </p><ul style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 16px;" class=""><li style="font-size: 18px;" class="">They are relatively short</li><li style="font-size: 18px;" class="">They are already well established for Apple app distribution</li><li style="font-size: 18px;" class="">They do not rely on a web address that may change should the repo move</li><li style="font-size: 18px;" class="">They are less likely to conflict with user names across repo hosts</li></ul><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">I’d imagine a package declaration that looks something like this:</p><pre style="color: rgb(17, 17, 17); font-size: 16px;" class=""><code class=" coffeescript hljs" style="display: block; padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial;"><span class="hljs-reserved">import</span> PackageDescription
<span class="hljs-reserved">let</span> package = Package(
<span class="hljs-attribute" style="color: rgb(0, 128, 128);">name</span>: <span class="hljs-string" style="color: rgb(221, 17, 68);">"SwiftString"</span>
<span class="hljs-attribute" style="color: rgb(0, 128, 128);">origin</span>: <span class="hljs-string" style="color: rgb(221, 17, 68);">"org.sadun"</span>
)</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">In the case of name conflicts instead of importing <code class="">SwiftString</code>, you’d prefix an origin:</p><pre style="color: rgb(17, 17, 17); font-size: 16px;" class=""><code class=" actionscript hljs" style="display: block; padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial;"><span class="hljs-preprocessor" style="color: rgb(153, 153, 153); font-weight: bold;"><span class="hljs-keyword" style="color: rgb(51, 51, 51);">import</span> org.sadun.SwiftString
<span class="hljs-keyword" style="color: rgb(51, 51, 51);">import</span> com.foobar.SwiftString</span></code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; font-size: 1.1429em; line-height: 1.3125em; margin: 1.3125em 0px;" class="">Ideally, you could further alias these to shorten symbol disambiguation:</p><pre style="color: rgb(17, 17, 17); font-size: 16px;" class=""><code class=" vim hljs" style="display: block; padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial;">import org.sadun.SwiftString <span class="hljs-keyword" style="font-weight: bold;">as</span> SadunStrings
import <span class="hljs-keyword" style="font-weight: bold;">com</span>.foobar.SwiftString <span class="hljs-keyword" style="font-weight: bold;">as</span> FoobarStrings
// Unique <span class="hljs-keyword" style="font-weight: bold;">to</span> <span class="hljs-keyword" style="font-weight: bold;">only</span> one package, <span class="hljs-keyword" style="font-weight: bold;">no</span> name conflict
uniqueMethod(<span class="hljs-string" style="color: rgb(221, 17, 68);">"Hello World"</span>)
// name collision disambiguation
SadunStrings.sharedMethod(<span class="hljs-string" style="color: rgb(221, 17, 68);">"Hello World"</span>)</code></pre><div class="">I'm interested in hearing any feedback and thoughts about whether this is possible and what I could do to help further this idea.</div></div></body></html>