[swift-evolution] [Thoughts?][Phase2] default arguments and trailing closure syntax

Xiaodi Wu xiaodi.wu at gmail.com
Wed Jan 4 22:27:58 CST 2017


The only difference between your proposed spelling and not using trailing
closures at all is the placement of the closing parenthesis, which is not
at all a clear enough win sufficient to justify having two spellings for
the same thing.

I'm of the same opinion that was expressed by Erica Sadun and Jordan Rose
last summer, that where a function takes more than one closure
argument--defaulted to nil or no--it's arguable that we ought to prohibit
trailing closures altogether for the sake of clarity.
On Wed, Jan 4, 2017 at 21:48 Saagar Jha via swift-evolution <
swift-evolution at swift.org> wrote:

> Check out this thread
> <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160606/020470.html>–it’s
> very similar to what you proposed, but it didn’t go anywhere. FWIW +1 to
> this as well as the ability to use multiple trailing closures like so:
>
> animate(identifier: “”, duration: 0, update: {
> // update
> }, completion: {
> // completion
> }
>
> Saagar Jha
>
>
>
> On Jan 4, 2017, at 6:25 PM, Jay Abbott via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> When you have a function with a closure and then another optional default =
> nil closure at the end, like this:
>
> open static func animate(identifier: String,
>                          duration: Double,
>                          update: @escaping AnimationUpdate,
>                          completion: AnimationCompletion? = nil) {
>
> You can’t use trailing closure syntax for the update argument when
> leaving the completion argument out/default.
>
> This kind of breaks one of the benefits of default arguments, which is
> that you can add them to existing released functions without breaking the
> calling code. This means you have to add a separate convenience function
> without the extra argument, which is annoying and inelegant. Another
> annoying thing is that you can easily miss this error if you happen to not
> use trailing closure syntax in your tests or other usage, because adding
> the extra default argument compiles fine for code that uses normal syntax.
>
> Are there any issues/gotchas if the trailing closure syntax were to work
> for the last *specified* argument rather than the last *defined* argument?
>> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170105/80233794/attachment.html>


More information about the swift-evolution mailing list