<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 24 Mar 2016, at 16:13, William Dillon <<a href="mailto:william@housedillon.com" class="">william@housedillon.com</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=""><blockquote type="cite" class=""><div class="">On Mar 24, 2016, at 7:18 AM, Kurt Werle 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 dir="ltr" class="">Coming from ruby, I'm quite fond of trailing closures. I couldn't really give you a concrete reason why - putting them in the ()'s really isn't that big a deal. But I'll say that I move them outside every single time...<div class=""><br class=""></div><div class="">I will say that your examples are the most trivial possible and that the more complex the closure (describing context variables and return types, throws, etc) the uglier it seem to me to put it inside parens.</div></div><div class="gmail_extra"><br class=""></div></div></blockquote></div><br class=""><div class="">Agree.</div><div class=""><br class=""></div><div class="">Another thing I like about trailing closures is that it allows me to make custom constructs that feel more like a part of the language. For example, I really love this extension for NSLock that I have:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">NSLock</span><span style="" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> protect(action: (</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">lock</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> action()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">unlock</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Now, whenever I need to use my lock, I can just do:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">peersLock</span><span style="" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">protect</span><span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> outputString += </span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">"</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">peers</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">count</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">) peers:\n"</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class="">, peer) </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">peers</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> outputString += </span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">"</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">peer</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">)\n"</span></div><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Helvetica; font-size: 12px;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">To me, it looks cleaner to me to not have this paren dangling around at the end. On this one I’d definitely say that if you don’t like it, don’t use it. I don’t *think* that you’re forced to use it anywhere. It’s a hard sell to take it away from everyone.</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">- Will</span></div></div></span></div></div></div></blockquote></div><br class=""><div class="">I’m not proposing to remove them entirely, in fact your lock example is a perfect example of when a trailing closure makes the most sense, as a form of customised language feature. But I’m wondering if perhaps cases like these should be created using an attribute that specifically enables it? e.g- your definition could become:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func protect(action: @trailing (Void) -> Void) { … }</font></div><div class=""><br class=""></div><div class="">It’s other cases like common usages of .map() and similar methods where I’ve found myself using the closure in its trailing form less and less, and am not as sure if it’s really needed, or may actually be more of a detriment to the language than a benefit.</div></body></html>