<div dir="ltr">And I'd prefer <font face="monospace, monospace">logIn</font> (verb) over <font face="monospace, monospace">login</font> (noun) in the example :)</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 23, 2016 at 12:07 PM, Thorsten Seitz 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><br></div><div><div><div><span class=""><blockquote type="cite"><div>Am 23.01.2016 um 01:35 schrieb Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:</div><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"><blockquote type="cite"><div><br>On Jan 22, 2016, at 5:26 PM, Michael Wells via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jan 23, 2016 at 12:00 AM, David Owens II via swift-evolution<span> </span><span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span><span> </span>wrote:<br><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 style="word-wrap:break-word"><blockquote type="cite"><div><div><b>Compensate For Weak Type Information as needed to clarify a parameter’s role.<br></b></div><div><br></div>Especially when a parameter type is NSObject, Any, AnyObject, or a fundamental type such Int or String, type information and context at the point of use may not fully convey intent. In this example, the declaration may be clear, but the use site is vague:<br><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="Menlo">func add(observer: NSObject, for keyPath: String)</font></div></div><div><div><font face="Menlo">grid.add(self, for: graphics) // vague</font></div></div></blockquote><div><br>To restore clarity, precede each weakly-typed parameter with a noun describing its role:<br><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="Menlo">func addObserver(_ observer: NSObject, forKeyPath path: String)</font></div><div><div><font face="Menlo">grid.addObserver(self, forKeyPath: graphics) // clear</font></div></div></blockquote></blockquote><div><br></div></div></blockquote></div></div></blockquote><br>Where this rule feels clumsy to me is in code such as<br><br><font face="Menlo">func loginWithUsername(username: String, password: String) -> Bool</font><br><br>vs.<br><br><font face="Menlo">func login(username: String, password: String) -> Bool<br></font><br>But maybe it just takes some time to get used to the style.</div></div></div></blockquote></div><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"><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">Consider an exception rule:</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">Prefer external names for the first parameter when the natural semantic relationship between the parameters is stronger than their relation to the operation. So</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">login(username: String, password:String)</div></div></blockquote><div><br></div></span><div>I would actually prefer one of</div><span class=""><div><br></div><font face="Menlo">func loginWithUsername(username: String, password: String)</font></span><div><span style="font-family:Menlo">func login(withUsername username: String, password: String)</span></div><div><div><br></div><div>because of the weak type information to just</div><div><div><span style="font-family:Menlo"><br></span></div><div><span style="font-family:Menlo">func login(sername: String, password: String)</span></div><div></div></div><div><br></div><div><br></div><div>Of course the ideal version would define the types Username and Password (ideally with a future newtype construct :-) and then could use just</div><div><div><span style="font-family:Menlo"><br></span></div><div><span style="font-family:Menlo">func login(username: Username, password: Password)</span></div><div></div></div></div><div><br></div><div><br></div></div><div><span class=""><blockquote type="cite"><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">but </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">addLineToPoint(p1: CGPoint, withThickness: CGFloat)</div></blockquote><div><br></div></span><div>Why should <font face="Menlo">addLineTo(point: CGPoint, withThickness thickness: CGFloat)</font> be considered as having weak type information for the point?</div><div><br></div><div><br></div><div>-Thorsten</div></div><br></div></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>