[swift-evolution] [Pitch] Allow trailing argument labels
Niels Andriesse
andriesseniels at gmail.com
Wed Feb 22 04:33:39 CST 2017
+1
I've encountered this issue myself on several occasions, and I think you'd
always be able to create a function signature that reads like a proper
sentence if this is implemented.
On Wed, Feb 22, 2017 at 9:24 PM, Patrick Pijnappel via swift-evolution <
swift-evolution at swift.org> wrote:
> I'd like to discuss allowing a trailing 'argument label' without an actual
> argument:
>
> func adding(_ other: Self, reportingOverflow) -> … // Actual case in
> SE-104 where this came up
> func tableView(_ tableView: UITableView, numberOfSections) -> Int //
> Referenced as tableView(_:numberOfSections)
>
> As illustrated above, the way we reference functions extends very
> naturally to include these.
>
> This would be very useful for several cases:
> • Delegate methods, which currently all start with the same prefix, except
> for some odd cases that really actually just needed a trailing argument
> label.
> • Cases where the function is a more specialized version of one with the
> same name, but can't use a flag because the return type is different (e.g.
> reportingOverflow), or the extra flag check is just undesirable. The
> standard library now uses some workarounds to achieve this (e.g. having a
> trailing argument of type void).
> • Function names that just work more naturally with some additional words
> after the last argument. If we allow trailing argument labels, you can form
> any sentence, rounding out the syntax.
>
> Overall, I think this could be the final missing piece to complete Swift's
> functions-as-sentences approach.
>
> _______________________________________________
> 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/20170222/9f9d8e33/attachment.html>
More information about the swift-evolution
mailing list