<div dir="ltr">The word "Type" is also blocked in most cases. So still being able to use the word "type" is less valuable anyway because you cannot create a nested type called "Type" and will most likely rename it to something like "Kind".<div><br></div><div>This is actually very annoying:</div><div><br></div><div><div><font face="monospace, monospace">struct Attachment {</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </span>let type: Type</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </span>enum Type {</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">                </span>case Image</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">                </span>case Video</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </span>}</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">let attachmentType = Attachment.Type // error: expected member name or constructor call after type name</font></div>
<div><br></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 7:24 PM, Jordan Rose via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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>".self" was chosen for a few reasons:</div><div><br></div><div>- The obvious choice was ".class", given precedent in Objective-C and Java, but not all types are classes.</div><div>- 'type' is a very common property name, so we have tried very hard to avoid taking it as a general keyword.</div><div>- 'type' also always implies going up a level. "obj.dynamicType" gives you back the type of 'obj', so wouldn't "SomeClass.type" give you back the <a href="http://sealiesoftware.com/blog/archive/2009/04/14/objc_explain_Classes_and_metaclasses.html" target="_blank">metaclass</a>? (Alternately, "SomeType.staticType' not being the same as 'SomeType.dynamicType" seems weird.)</div><div>- 'self' is already a keyword.</div><div>- ".self" actually works in Objective-C as well.</div><div>- ".self" currently also applies to instances, doing exactly what you think it does. This is <i>nearly</i> useless. In theory you could use it to unwrap one level of optionality ("doubleOpt?.self") but that doesn't actually work today.</div><div><br></div><div>I read "SomeType.self" as "SomeType itself, rather than an instance of it (or associated type)".</div><div><br></div><div>(And before someone brings it up, we chose not to just allow "SomeType" on its own because "let x = SomeType" is a likely typo for "let x: SomeType".)</div><div><br></div><div>I think coming up with a clearer name is possible here, but there's plenty to consider. Still, certainly a reasonable thing to bring up.</div><div><br></div><div>Best,</div><div>Jordan</div><div><br></div><div><blockquote type="cite"><div><div class="h5"><div>On Dec 15, 2015, at 8:42 , Brandon Knope via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br></div></div><div><div><div class="h5"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Doh! staticType is the obvious choice!</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I agree that adding more keywords can be bad, but in this case I think the clarity outweighs any downside:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">SomeType.staticType</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">SomeType.self </div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">To me (and I'm sure many others) one is vastly more obvious and easier to understand. </div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I still don't really understand what SomeType.self is trying to convey upon first glance</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Brandon </div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>Sent from my iPad</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>On Dec 15, 2015, at 11:34 AM, Dennis Lysenko <<a href="mailto:dennis.s.lysenko@gmail.com" target="_blank">dennis.s.lysenko@gmail.com</a>> wrote:<br><br></div><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><div dir="ltr">+1. Side effects can be eliminated through code migration if a suitable property name is chosen. Perhaps `staticType` to continue in the vein of `dynamicType`? <div><br></div><div>Main detractor is that creating more keywords isn't necessarily a good thing.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 15, 2015 at 11:19 AM Brandon Knope via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><span></span>One area of swift that is really not clear to me is when you want to use the type of a class, struct, enum, etc as a value. </div><div><br></div><div>Metatyping is explained here: <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-XID_1022" target="_blank">https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-XID_1022</a></div><div><br></div><div>Example: <ol style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none"><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">let</span><span> </span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">metatype</span><span style="background-color:rgba(255,255,255,0)">:<span> </span></span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">SomeClass</span><span style="background-color:rgba(255,255,255,0)">.</span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">Type</span><span style="background-color:rgba(255,255,255,0)"><span> </span>= SomeClass.</span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">self</span></font></code></li></ol><div><br></div><div>Is there a reason why this isn't <span style="background-color:rgba(255,255,255,0)">SomeClass.</span>type? Everywhere in the document this is explained as returning the type yet it's using a postfix self to access the type. </div><div><br></div><div>I propose changing the postfix self to something more obvious like "type"</div><div><br></div><div>Going back to the example:</div><div><ol style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none"><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">let</span><span> </span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">metatype</span><span style="background-color:rgba(255,255,255,0)">: SomeClass.</span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">Type</span><span style="background-color:rgba(255,255,255,0)"><span> </span>= SomeClass.type</span></font></code></li></ol><div><br></div></div><div>Several reasons why I think this is better:</div><div>1. Postfix self is not obvious as an option as you never see a postfix self anywhere else </div><div>2. "self" does not clearly explain that the type is being returned </div><div>3. ObjC programmers are familiar with accessing the class type by sending the "class" method to the class type. In this case it needs to work on structs and enums, so a "type" method would make more sense. </div><div>4. Instances have a dynamicType method. For consistency, classes, structs, etc., should have a type method</div><div><br></div><div>Any other suggestions would be welcome. </div><div><br></div><div>Brandon </div><span></span><br><span>Sent from my iPad</span><br></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPcMHsgQz33SrTbIBqh0dxknVxlPrKM0qDNDweGmZL1cMon3PZ86xs9skTnDn9Mn1zx1MxqQrWOqohYw-2BZuIliB4PP8pQkkyelHQxAWhhF1ffVk7-2F-2FYeJOfDcoz-2BBqTCHovFaF7LhZjwOQBBfBVHeCCYOqT6MJXwWRJr17QyAt9KJtBNrY4R0LnkavP7Rf5ghMc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"></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></blockquote></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSBU0O-2Fi1NF8tA7GaalX8cmwIU7WEl2pbyDNPPOi-2BYh-2BLE4v-2FpiJY9lSBlsmwJfgoiSOtJiuVJ6kvmGDuq7RId15VtsMr6M4r9fwXYFRLiYqBXoRDm7yAmZjCP-2BZTnlu-2BTPGuSLzXOIW4uEK7ytZYkoJ4zXJ6YNaCCMXpwE72Vx4bCmYJR3ZL3mHSqdrL73w0-2BA-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span></span><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><span class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=6ZGE61OxINd5lLe2xYh9Ku-2BXbixWNr2nvfzp2IB1sZgIq7nubdqvpTFedG4b15cb7zReHZJxNCWroHb-2FFE363A8-2Fvob3xjGYlUVJPhXWR-2Bx-2F7pbtf9-2ByfucUxe43dQQZBaz-2B8y7fsq3E0ByZWDtiwdaKlDLeSevxp7JneNhmtDYNLDNza-2FBlyd-2B3ycU45vLSO6l01Rf5JogWd6hLf7I09YGsqmp-2FUSnLGwJTmK1v6JY-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>
<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>