<div dir="ltr"><div>+1 from me.</div><div><br></div>This has apparently become my schtick but the structs are definitely initializable. Make them enums with no case to guard against initialization.<div><br></div><div>``` swift</div><div><span style="color:rgb(0,0,0);font-family:&#39;Courier New&#39;;font-size:13px">extension AreaOfConcern {</span></div><div><span style="color:rgb(0,0,0);font-family:&#39;Courier New&#39;;font-size:13px">    init() {</span><span style="color:rgb(0,0,0);font-family:&#39;Courier New&#39;;font-size:13px">}</span></div><div><font color="#000000" face="Courier New">}</font></div><div>```</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 20, 2016 at 9:55 AM, Jared Sinclair 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"><div style="word-wrap:break-word"><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><b>TL;DR</b></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">I’d like to be able to group related internal entities within a namespace declaration, without having to fake it with non-initializable structs:</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="margin:0px"><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><font face="Courier New">internal namespace AreaOfConcern {</font></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><span style="font-family:&#39;Courier New&#39;">  let SomeString = “SomeString”</span></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><span style="font-family:&#39;Courier New&#39;">  let SomeInt = 42</span></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><span style="font-family:&#39;Courier New&#39;">  func checkSomething() -&gt; Bool {…} </span><span style="font-family:&#39;Courier New&#39;">  </span></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><font face="Courier New">}</font></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><font face="Courier New"><br></font></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><font face="Courier New"><br></font></div><div style="color:rgb(0,0,0);font-size:13px;font-family:Helvetica,Arial;margin:0px"><b>Rationale</b></div></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">Often within a module I find myself wanting to group related <b>internal</b> entities together within a namespace. Free functions and constants are a good example:</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">internal let SomeString = “SomeString”</font></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">internal let SomeInt = 42</font></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">internal func checkSomething() -&gt; Bool {…} </font></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New"><br></font></div><div style="color:rgb(0,0,0);margin:0px">So are thematically-related structs:</div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New"><br></font></div><div style="color:rgb(0,0,0);margin:0px"><span style="font-family:&#39;Courier New&#39;">internal struct CreateANote: Endpoint {</span></div><div style="margin:0px"><font face="Courier New">  // ...</font></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">}</span></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">internal struct UpdateANote: Endpoint {</span></div><div style="margin:0px"><div style="margin:0px"><font face="Courier New">  // ...</font></div></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">}</span></div><div style="margin:0px"><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">internal struct DeleteANote: Endpoint {</span></div><div style="margin:0px"><div style="margin:0px"><font face="Courier New">  // ...</font></div></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">}</span></div></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">The best way to approximate this currently is to wrap them in a struct, like:</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">internal struct AreaOfConcern {</font></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">  static let SomeString = “SomeString”</font></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  static</span><span style="font-family:&#39;Courier New&#39;"> </span><span style="font-family:&#39;Courier New&#39;">let SomeInt = 42</span></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  static</span><span style="font-family:&#39;Courier New&#39;"> </span><span style="font-family:&#39;Courier New&#39;">func checkSomething() -&gt; Bool {…} </span></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">}</font></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New"><br></font></div><div style="color:rgb(0,0,0);margin:0px">or for thematically-related structs, to enable tidy usage for the callers:</div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New"><br></font></div><div style="margin:0px"><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">internal struct NoteEndpoints {</font></div><div style="color:rgb(0,0,0);margin:0px"><span style="font-family:&#39;Courier New&#39;">  struct Create: Endpoint {</span></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">    // ...</font></div><div style="color:rgb(0,0,0);margin:0px"><span style="font-family:&#39;Courier New&#39;">  }</span></div><div style="color:rgb(0,0,0);margin:0px"><span style="font-family:&#39;Courier New&#39;">  struct Update: Endpoint {</span></div><div style="color:rgb(0,0,0);margin:0px"><div style="margin:0px"><font face="Courier New">    // ...</font></div></div><div style="color:rgb(0,0,0);margin:0px"><span style="font-family:&#39;Courier New&#39;">  }</span></div><div style="color:rgb(0,0,0);margin:0px"><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  struct Delete: Endpoint {</span></div><div style="margin:0px"><div style="margin:0px"><font face="Courier New">    // ...</font></div></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  }</span></div></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New">}</font></div><div style="color:rgb(0,0,0);margin:0px"><font face="Courier New"><br></font></div><div style="margin:0px"><font face="Courier New">let endpoint = NoteEndpoints.Create(text: String, …)</font></div></div><div><br></div>This solution is somewhat awkward because <span style="font-family:&#39;Courier New&#39;">AreaOfConcern</span> and <span style="font-family:&#39;Courier New&#39;">NoteEndpoints</span> are not really being used as structs so much as an informal namespaces. To communicate this to internal users (and to discourage them from trying to initialize these wrapper structs), you can give them private initializers (which is even more awkward, but helpful):<div><br></div><div><div style="margin:0px"><font face="Courier New">internal struct AreaOfConcern {</font></div><div style="margin:0px"><font face="Courier New">     </font><span style="font-family:&#39;Courier New&#39;">static</span><span style="font-family:&#39;Courier New&#39;"> </span><span style="font-family:&#39;Courier New&#39;">let SomeString = “SomeString”</span></div><div style="margin:0px"><font face="Courier New">     </font><span style="font-family:&#39;Courier New&#39;">static</span><span style="font-family:&#39;Courier New&#39;"> </span><span style="font-family:&#39;Courier New&#39;">let SomeInt = 42</span></div><div style="margin:0px"><font face="Courier New">     </font><span style="font-family:&#39;Courier New&#39;">static</span><span style="font-family:&#39;Courier New&#39;"> </span><span style="font-family:&#39;Courier New&#39;">func checkSomething() -&gt; Bool {…} </span></div><div style="margin:0px"><font face="Courier New"><br></font></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">     private init()</span></div><div style="margin:0px"><font face="Courier New">}</font></div><div style="margin:0px"><font face="Courier New"><br></font></div><div style="margin:0px">It would be preferable if there was another keyword, perhaps <span style="font-family:&#39;Courier New&#39;">namespace</span>, that could be used as follows:</div><div style="margin:0px"><br></div><div style="margin:0px"><div style="margin:0px"><div style="margin:0px"><font face="Courier New">internal namespace NoteEndpoints {</font></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  struct Create: Endpoint {</span></div><div style="margin:0px"><font face="Courier New">    // ...</font></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  }</span></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  struct Update: Endpoint {</span></div><div style="margin:0px"><div style="margin:0px"><font face="Courier New">    // ...</font></div></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  }</span></div><div style="margin:0px"><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  struct Delete: Endpoint {</span></div><div style="margin:0px"><div style="margin:0px"><font face="Courier New">    // ...</font></div></div><div style="margin:0px"><span style="font-family:&#39;Courier New&#39;">  }</span></div></div><div style="margin:0px"><font face="Courier New">}</font></div><div style="margin:0px"><font face="Courier New"><br></font></div><div style="margin:0px">The namespace keyword would follow all the same scope and dot-notation rules as a structs, but would not be initializable.</div></div></div><span class="HOEnZb"><font color="#888888"><div><br><div><div style="font-family:helvetica,arial;font-size:13px">-- <br>Jared Sinclair<br>Sent with Airmail</div></div></div></font></span></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
<br></blockquote></div><br></div>