<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>100% agree that using a struct this way is far from ideal. I just don't think the problem here is realistically that big of a deal.&nbsp;</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">If there were major performance gains to be had from the compiler knowing a data structure was essentially a set of grouped constants, then I would completely support adding a keyword to indicate such. I don't believe that's the case though, as it stands I believe both your proposal <b>and</b> my alternative are just syntactic sugar with the potential for confusion.</div><div><br>On Dec 13, 2015, at 18:16, T.J. Usiyan &lt;<a href="mailto:griotspeak@gmail.com">griotspeak@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">The use case described in the proposal and your response doesn't use structs as a "bucket of values". I uses *the type* as a bucket of values. The point of using an empty enum is to emphasize this point. The overal point of this proposal is to introduce semantics that obviate the need to 'decide' between enum and struct since neither are the type actually desired. I suggest using an enum as the implementation with the hope that it will simplify implementation.<div><br></div><div>Your suggestion of `static struct` emphasizes the utility of a namespace keyword. Is `static struct …` a declaration of a type or an instance and of what?&nbsp;</div><div><div><br></div><div>TJ</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 13, 2015 at 6:44 PM, Cole Kurkowski <span dir="ltr">&lt;<a href="mailto:crk@fastmail.com" target="_blank">crk@fastmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>IMO using <span style="background-color:rgba(255,255,255,0)">&nbsp;an enum is non-intuitive. A struct is a "bucket of values" and so makes fits with the usage here. If the ability to instantiate the NotificationNames struct is a problem, adding a&nbsp;</span></div><div><br><div><span style="background-color:rgba(255,255,255,0)">private init()&nbsp;</span></div><div><span style="background-color:rgba(255,255,255,0)">{</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">}</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">seems more intuitive than co-opting an enum, which has a fairly established use case.&nbsp;</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">Your proposal would essentially be adding a keyword that is transformed back into "enum" during compilation. I don't think that a relatively minor improvement in clarity for a fairly small use case is worth adding a language feature.</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">Allowing structs to be declared as static would be another way of simplifying this kind of declaration, i.e.</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">static struct NotificationNames {</span></div><div><span style="background-color:rgba(255,255,255,0)">&nbsp; &nbsp; &nbsp;let userDataChanged = ...</span></div><div><span style="background-color:rgba(255,255,255,0)">&nbsp; &nbsp; &nbsp;let recievedAlert = ...</span></div><div><span style="background-color:rgba(255,255,255,0)">}</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">This would allow dropping the private init declaration and dropping the static from each property. I'm not sure I think this shortcut is necessary or even if it's a good idea, but I do think it fits with the language a little better than your current proposal.&nbsp;</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div></div><div><div class="h5"><div>On Dec 11, 2015, at 04:39, T.J. Usiyan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div></div></div><blockquote type="cite"><div><div><div class="h5"><div dir="ltr"><div>Namespaces</div><div>Author(s): TJ Usiyan</div><div><br></div><div>Introduction</div><div><br></div><div>A `namespace` keyword for swift hold related global variables.</div><div><br></div><div>Motivation</div><div><br></div><div>We often want to collect related variables which do not, for whatever reason, fit neatly into a type provided by Swift. Importing Objective C 'magic strings' as Joshua Sullivan does [here] is one such example. The solution he arrives at is a `struct` type with many type variables and no fields.</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>struct NotificationNames {</div><div><span style="white-space:pre-wrap">        </span> &nbsp;static let userDataChanged = "UserDataChangedNotificationName"</div><div><span style="white-space:pre-wrap">        </span> &nbsp;static let receivedAlert = "ReceivedAlertNotificationName"</div><div><span style="white-space:pre-wrap">        </span> &nbsp;static let peanutButterJellyTime = "ItsPeanutButterJellyTimeNotificationName"</div><div><span style="white-space:pre-wrap">        </span>}</div><div><br></div><div>Users of this API are not meant to create instances of this type, yet it is still possible. A solution to this is to use an `enum` without cases.&nbsp;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>enum NotificationNames {</div><div><span style="white-space:pre-wrap">        </span> &nbsp;static let userDataChanged = "UserDataChangedNotificationName"</div><div><span style="white-space:pre-wrap">        </span> &nbsp;static let receivedAlert = "ReceivedAlertNotificationName"</div><div><span style="white-space:pre-wrap">        </span> &nbsp;static let peanutButterJellyTime = "ItsPeanutButterJellyTimeNotificationName"</div><div><span style="white-space:pre-wrap">        </span>}</div><div><br></div><div>No instances of the `enum` can be made. That this inability to create an instance is intentional is only conveyed via the type system.&nbsp;</div><div><br></div><div>Proposed solution</div><div><br></div><div>Clarity would be greatly improved if we could use `namespace` as a synonym for an enum with no cases. This would allow us to avoid repetition of `static` as well.</div><div><br></div><div><span style="white-space:pre-wrap">        </span>namespace NotificationNames {</div><div><span style="white-space:pre-wrap">        </span> &nbsp;let userDataChanged = "UserDataChangedNotificationName"</div><div><span style="white-space:pre-wrap">        </span> &nbsp;let receivedAlert = "ReceivedAlertNotificationName"</div><div><span style="white-space:pre-wrap">        </span> &nbsp;let peanutButterJellyTime = "ItsPeanutButterJellyTimeNotificationName"</div><div><span style="white-space:pre-wrap">        </span>}</div><div><br></div><div>Detailed design</div><div><br></div><div>Namespaces can be represented in the type system as enums. All variables declared in a namespace's scope would be type variables.</div><div><br></div><div>Impact on existing code</div><div><br></div><div>This is an additive change and, as such, should not break any existing code. Though it doesn't matter, this addition could possibly attain ABI compatibility if namespaces are represented as enums without cases.</div><div><br></div><div>Alternatives considered</div><div><br></div><div>Don't implement namespaces. Developers could continue(begin?) using an empty enum to hold type variables.</div></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=-2Bxb47WeGoqMoAgzLM1ObomDZ33eAoWUyfgnPK0aY0kmOBV0UOL-2F-2FewTnMlFakhgehvwInLhXqOSgLWhWSC59AspLa6GqGYZeh-2BtdIo20WyqWuINj3rtuE9qLd-2BiL4jagc5HtjH2Ce0ulfeDXCmavB061BWZFQBdbt3RewD1Vr7Qm8vt6InljqJC-2FSC7yR9nSfTzLs3qbGWpKpC-2BzjutEtkq79cco-2BGmJif1-2BbbIwACs-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></blockquote><span class=""><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></span></div></blockquote></div><br></div>
</div></blockquote></body></html>