<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="">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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><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 dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><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 style="margin:0 0 0 40px;border:none;padding:0px" class=""><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 style="margin:0 0 0 40px;border:none;padding:0px" class=""><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=""><div class=""><br class=""></div><div class="">Consider an exception rule:</div><div class=""><br class=""></div><div class="">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=""><br class=""></div><div class="">login(username: String, password:String)</div><div class="">moveTo(x: Double, y: Double)</div><div class=""><br class=""></div><div class="">but </div><div class=""><br class=""></div><div class="">addLineToPoint(p1: CGPoint, withThickness: CGFloat)</div><div class=""><br class=""></div><div class="">-- Erica</div><div class=""><br class=""></div></body></html>