<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, May 20, 2016 at 8:48 AM Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com">matthew@anandabits.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On May 20, 2016, at 10:27 AM, Tony Allevato via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr"><div>Another use case to consider: code generation. There, namespaces can be vital; they let you isolate code that you may have no real control over (for example, data models that correspond to remote services) from the rest of your code to avoid collisions. In some cases that can be achieved by putting the shared code in its own module, but if that data description format has hierarchical namespaces/packages of its own (Google&#39;s protocol buffers, for example), then the lack of namespaces forces the code generator to come up with contrived schemes for naming nested entities (like the Objective-C implementation, which uses underscore_delimited_names). The result is that Swift code using those services would look *very* unnatural.</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>What benefits do namespaces provide that empty enums and / or submodules do not?  This isn’t clear to me and I think it is an essential part of the case that must be made.<span style="line-height:1.5"> </span></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>Nobody is arguing that we don’t need a way to isolate names.  The question is whether namespaces are the right mechanism for doing that or not.</div></div></div></blockquote><div><br></div><div>I&#39;m certainly flexible on the way that organization manifests itself. In a general sense, u<span style="line-height:1.5">sing structs-with-private-initializers or enums seems like abuse of those constructs. Generic types also can&#39;t be nested yet (but this is well-known and on the list of things to fix).</span></div><div><br></div><div>Some other concerns from my own experience in the domain of code generation:</div><div><br></div><div>I need to be able to define namespaces/organization in the source code, not as an artifact of the build system, which may prevent submodules from working as intended. Unless we want to be so prescriptive as to say, this is the One True Way that you will build your Swift code and nothing else matters, in which case I could probably generate a companion Swift package manifest.</div><div><br></div><div>Would submodules support circular references between them? If module Foo.Bar has a type that references something in Foo.Baz, and Foo.Baz has a type that references something in Foo.Bar, will that import work (they don&#39;t even have to be circular references between two *types*, just different types within two *modules*)? If it&#39;s like regular top-level modules now, that&#39;s not possible, because A can&#39;t import B if B imports A.</div><div><br></div><div>Structs/enums as faux namespaces also fall apart if you try to link multiple build artifacts into the same library or executable. Let&#39;s say I&#39;m using a code generator to generate types from a data model that defines a namespace Foo. Let&#39;s go on to say that, due to the way the dependencies of my project are structured, the code for type Foo.Bar is generated separately from Foo.Baz. <span style="line-height:1.5">Each run of the code generator needs to be independent, so in order to do that, it defines an empty Foo struct and extend it with the types inside that namespace that are generated in that run.</span><span class="inbox-inbox-Apple-converted-space" style="line-height:1.5"> So, in one run I have this:</span></div><div><br></div><div>generated1/Foo.swift:</div><div>public struct Foo { private init() {} }</div><div><br></div><div><span style="line-height:1.5">generated1</span><span style="line-height:1.5">/</span>Foo.Bar.swift:</div><div>extension Foo {</div><div>  struct Bar { ... }</div><div>}</div><div><br></div><div>and in another run, I have this:</div><div><div><br></div><div><span style="line-height:1.5">generated2</span><span style="line-height:1.5">/</span>Foo.swift:</div><div>public struct Foo { private init() {} }</div><div><br></div><div><span style="line-height:1.5">generated2</span><span style="line-height:1.5">/</span>Foo.Baz.swift:</div><div>extension Foo {</div><div>  struct Baz { ... }</div><div>}</div><br class="inbox-inbox-Apple-interchange-newline"></div><div>I have two copies of the Foo struct, so I can&#39;t easily compile these sources into object files and then pull them all together to link. Even though Foo doesn&#39;t contain anything other than nested types, the compiler outputs metadata symbols for Foo itself that causes duplicate link errors.</div><div><br></div><div>Swift as it is today already gets me *almost* the whole way there—merging the .swiftmodules produced from the builds above works fine and results in a module that defines both Bar and Baz inside Foo. Essentially, my use case would be solved if I could somehow say &quot;Foo is not actually a type, it&#39;s used for organization and name mangling only, so please don&#39;t include any symbols for it alone in the output binary&quot;. Then everything would link correctly.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, May 20, 2016 at 8:08 AM T.J. Usiyan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">+1 for namespaces. </div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 20, 2016 at 10:52 AM, Haravikk via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
&gt; On 20 May 2016, at 14:51, Krystof Vasa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; When you have namespaces Car and Animal and each contains a class called List, IMHO there should be classes CarList and AnimalList. It&#39;s more verbose, but you imediately know which class is being used in opposite of just using List.<br>
<br>
</span>Why not use Car.List and Animal.List when its unclear from context? With Swift’s type inference you don’t often need to specify types anyway so your editor will know which list type you’re using based on how you obtained it.<br>
<br>
That said it does depend on the purpose of each List; do they have any commonality? They could for example both be generic List implementations, but were never factored out into a common module. If however they are specialised constructs specific to cars or animals, then the prefix may make most sense.<br>
<br>
For example, in the libdispatch thread the naming of Dispatch.DispatchQueue was queried, however this isn’t a general purpose queue type, it’s more specialised than that, so a name of “Queue” doesn’t convoy enough information, just as List might not. But it depends on what it actually does, which a basic example tends not to include ;)<br>
<br>
<br>
Anyway, I’m +1 for namespaces everywhere, some names can be common. For example Node could be related to trees, physics engines and all sorts of constructs. “Node” may be a perfectly fine name for these. That said, these are sometimes tied to specific types in which case nesting them may make more sense, which I believe is already being addressed (currently we can’t nest generic types)? It’s certainly not as simple as it can appear!<br>
<div><div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></blockquote></div></div>