<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="">Le 15 févr. 2016 à 11:58, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="font-size: 16px;" class="">While discussing leading enumeration dot prefixes, Howard Lovatt asked why static properties and methods could not be inferred via a dot prefix as well. Based on Swift-Evolution conventions, here's a new thread to discuss this idea: specifically, would it be beneficial (and/or possible) to use dot prefixes to denote static member references in instance member code.</div><div style="font-size: 16px;" class=""><br class=""></div><div style="font-size: 16px;" class="">Howard wrote:</div><div style="font-size: 16px;" class=""><br class=""></div><div style="font-size: 16px;" class=""></div><blockquote type="cite" style="font-size: 16px;" class=""><div class=""><span style="font-family: Palatino-Roman;" class="">+1 for the proposal, it is wierd to use `.` in some places and not others. </span><div style="font-family: Palatino-Roman;" class=""><br class=""></div><div style="font-family: Palatino-Roman;" class="">On the subject of static methods and properties in general, would it be possible for `.name` to be a reference to a static and `name` a reference to an instance? EG:</div><div style="font-family: Palatino-Roman;" class=""><br class=""></div><div class=""><font face="Menlo" class=""> .name = x // static</font></div><div class=""><font face="Menlo" class=""> name = x // instance</font></div><div class=""><font face="Menlo" class=""> x = name + .name // instance + static</font></div><div class=""><font face="Menlo" class=""> r = name ... .name // instance ... static, needs space</font></div><div class=""><font face="Menlo" class=""> r = name...Type.name // Can still qualify with type name</font></div></div><div style="font-family: Palatino-Roman;" class=""><br class=""></div></blockquote><div style="font-size: 16px;" class=""><br class=""></div><span style="font-size: 16px;" class="">Under the current system, you must explicitly name or derive a type to access static members from instance member implementations.</span><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> MyStruct {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> staticMember() {}</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> instanceMember() {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="color: rgb(0, 132, 0);" class=""> // name a type</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(79, 129, 135);" class="">MyStruct</span>.<span style="color: rgb(49, 89, 93);" class="">staticMember</span>() <span style="color: rgb(0, 132, 0);" class="">// works</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="color: rgb(0, 132, 0);" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="color: rgb(0, 132, 0);" class=""> // derive a type</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="" class=""> </span>self<span style="" class="">.</span>dynamicType<span style="" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">staticMember</span><span style="" class="">() </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// works</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""> </div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// error: value of tuple type '()' has no member 'staticMember'</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// does not work</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""> .staticMember()</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">}</div><div class=""><br class=""></div><div style="font-size: 16px;" class="">Using dot prefixes for static member access:</div></div><div style="font-size: 16px;" class=""><br class=""></div><div style="font-size: 16px;" class="">* Has precedent in enumeration members</div><div style="font-size: 16px;" class="">* Would streamline Swift code</div><div style="font-size: 16px;" class="">* Is visually differentiated from `self`-prefixed instance member references</div><div style="font-size: 16px;" class=""><br class=""></div><div style="font-size: 16px;" class="">What are your thoughts, both technical and philosophical, on a change like this? Thanks in advance for your feedback.</div></div></div></blockquote><br class=""></div><div><br class=""></div><div>Not sure if it’s valid concern, but the current shorthand is based on the immediate context of comparison/pattern matching. Adding shorthand here for static member reference within the class could introduce some resolution conflicts. </div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span> MyEnum {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> one</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> two</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> stillOne() -> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyEnum</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">one</span> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> data:<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyEnum</span> = .<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">one</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> .<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">stillOne</span>() <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">==</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">data</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Something!"</span>) }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> MyStruct {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> data:<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyEnum</span> = .<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">one</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> stillOne() -> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> data <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">==</span> .<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">one</span> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> instanceMember() {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> .<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">stillOne</span>() <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">==</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">MyStruct</span>.data { <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Something"</span>) } <span style="color: rgb(0, 132, 0);" class="">// This currently work</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div class=""><br class=""></div></div><div>The current logic easily resolves the code inside instanceMember() as a shorthand to MyEnum, but if we expand the shorthand as describe, will it make it too hard on the compiler.</div><div><br class=""></div><div><br class=""></div><div>Dany</div><br class=""></body></html>