<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=""><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">Am 23.01.2016 um 01:35 schrieb Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 22, 2016, at 5:26 PM, Michael Wells via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""><blockquote type="cite" class=""><div class="gmail_extra"><div class="gmail_quote">On Sat, Jan 23, 2016 at 12:00 AM, David Owens II via swift-evolution<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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 class="" style="word-wrap: break-word;"><blockquote type="cite" class=""><div class=""><div class=""><b class="">Compensate For Weak Type Information as needed to clarify a parameter’s role.<br class=""></b></div><div class=""><br class=""></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 class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class=""><font face="Menlo" class="">func add(observer: NSObject, for keyPath: String)</font></div></div><div class=""><div class=""><font face="Menlo" class="">grid.add(self, for: graphics) // vague</font></div></div></blockquote><div class=""><br class="">To restore clarity, precede each weakly-typed parameter with a noun describing its role:<br class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><font face="Menlo" class="">func addObserver(_ observer: NSObject, forKeyPath path: String)</font></div><div class=""><div class=""><font face="Menlo" class="">grid.addObserver(self, forKeyPath: graphics) // clear</font></div></div></blockquote></blockquote><div class=""><br class=""></div></div></blockquote></div></div></blockquote><br class="">Where this rule feels clumsy to me is in code such as<br class=""><br class=""><font face="Menlo" class="">func loginWithUsername(username: String, password: String) -> Bool</font><br class=""><br class="">vs.<br class=""><br class=""><font face="Menlo" class="">func login(username: String, password: String) -> Bool<br class=""></font><br class="">But maybe it just takes some time to get used to the style.</div></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Consider an exception rule:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 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 class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">login(username: String, password:String)</div></div></blockquote><div><br class=""></div><div class="">I would actually prefer one of</div><div class=""><br class=""></div><font face="Menlo" class="">func loginWithUsername(username: String, password: String)</font><div class=""><span style="font-family: Menlo;" class="">func login(withUsername username: String, password: String)</span></div><div class=""><div class=""><br class=""></div><div class="">because of the weak type information to just</div><div class=""><div class=""><span style="font-family: Menlo;" class=""><br class=""></span></div><div class=""><span style="font-family: Menlo;" class="">func login(sername: String, password: String)</span></div><div class=""></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">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 class=""><div class=""><span style="font-family: Menlo;" class=""><br class=""></span></div><div class=""><span style="font-family: Menlo;" class="">func login(username: Username, password: Password)</span></div><div class=""></div></div></div><div><br class=""></div><div><br class=""></div></div><div><blockquote type="cite" class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">but </div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">addLineToPoint(p1: CGPoint, withThickness: CGFloat)</div></blockquote><div><br class=""></div><div class="">Why should <font face="Menlo" class="">addLineTo(point: CGPoint, withThickness thickness: CGFloat)</font> be considered as having weak type information for the point?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-Thorsten</div></div><br class=""></div></div></body></html>