<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></div><div><br>Am 08.06.2016 um 22:59 schrieb Paul Cantrell via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div><br class=""><blockquote type="cite" class="">On Jun 8, 2016, at 3:46 PM, Jordan Rose via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" style="font-family: HelveticaNeue; font-size: 13px; font-style: normal; font-variant-caps: 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=""><br class="">On Jun 8, 2016, at 12:06, Matt Neuburg via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">Stop me if you've heard this one; I've only just joined the list, in order to raise it.<br class=""><br class="">Here's a common thing to say:<br class=""><br class=""> UIView.animate(withDuration:0.4, animations: {<br class=""> self.v.backgroundColor = UIColor.red()<br class=""> })<br class=""><br class="">That's ugly. I'd rather write:<br class=""><br class=""> UIView.animate(withDuration:0.4) {<br class=""> self.v.backgroundColor = UIColor.red()<br class=""> }<br class=""><br class="">What stops me is that `animations:` is not eligible for trailing closure syntax, because it isn't the last parameter — `completion:` is. But `completion:` has a default value, namely `nil` — that's why I'm allowed to omit it. So why can't the compiler work its way backwards through the parameters, and say to itself: "Well, I see a trailing closure, and I don't see any `animations:` label or any `completion:` label, so this trailing closure must be the `animations:` argument and the `completions:` argument must be `nil`."<br class=""><br class="">The idea is that this would work for _any_ function call where the function takes, as its last parameters, a series of function arguments that have default values. There can be only one trailing closure, so it should be assumed to occupy the first available slot, as it were.<br class=""><br class="">Would this be viable? Would it make a decent proposal? m.<br class=""></blockquote><br class="">I'm one of those in favor of going the other way: if a function takes multiple closure arguments, you shouldn't be allowed to use a trailing closure at all, because it may not be obvious to readers of your code which one you are using. (This is especially true if the closures have the same signature.)<br class=""></blockquote><br class=""><div class="">I’m not in favor of that. Good argument labeling can make it perfectly clear to readers.</div><div class=""><br class=""></div><div class="">Siesta even leans on this feature a bit in one of its API methods:</div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 10.5px;" class=""> configure(whenURLMatches: </span><span style="font-size: 10.5px; font-variant-ligatures: no-common-ligatures;" class="">{ </span><span style="font-size: 10.5px; font-variant-ligatures: no-common-ligatures;" class="">$0 != </span><span style="font-size: 10.5px; font-variant-ligatures: no-common-ligatures;" class="">authentication.url }</span><span style="font-size: 10.5px;" class="">) {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> $0.config.headers[</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(132, 62, 100);" class="">"authentication-token"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.accessToken</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div></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="">…with this local refactoring if the first closure grows unwieldy:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> specialFancyResources = {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="color: rgb(183, 188, 179); font-size: 10.5px;" class="">// Special fancy matching goes here</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> configure(whenURLMatches: specialFancyResources) {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> $0.config.headers[</span><span style="font-variant-ligatures: no-common-ligatures; color: #843e64" class="">"authentication-token"</span><span style="font-variant-ligatures: no-common-ligatures" class="">] = </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.accessToken</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div></div><div class=""><br class=""></div><div class="">Both of those forms seem readable to me. I’d hate to rule them out.</div></div></blockquote><div><br></div>+1<div><br></div><div>-Thorsten </div><div><br></div><div><br><blockquote type="cite"><div><div class=""><br class=""></div><div class="">Cheers, P</div><div class=""><br class=""></div><div class=""><br class=""></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></body></html>