[swift-evolution] Allowing trailing commas in argument lists

Jonathan Tang jonathan.d.tang at gmail.com
Thu Mar 10 15:40:23 CST 2016


On Thu, Mar 10, 2016 at 12:27 PM, Erica Sadun via swift-evolution <
swift-evolution at swift.org> wrote:

> On 10 Mar 2016, at 17:28, Radosław Pietruszewski <radexpl at gmail.com>
> wrote:
>
> Trailing comma is not nonsensical, there is a specific purpose in allowing
> it (unlike your examples), and there’s precedent in Swift already.
>
>
> Trailing commas enable easier re-ordering of arguments, simplify growing
> or compacting argument lists, and do no harm.
>
> Their use in arrays and dictionaries are conventional enough that
> experienced programmers will not be surprised by their
> presence. No one will force their use and one's internal style guide (and
> linters) can direct whether any individual group
> adopts or ignores the addition.
>
> For those of us who prefer trailing commas, it will be both a convenience
> and an asset. For those against, there's no harm
> done. I find it unlikely that trailing commas will naturally lead to any
> unsafe code or produce a net negative effect on the
> language or the code-base it supports.
>
>
>
One concern I have is whether it might paint Swift into a corner later in
terms of the syntax it may adopt for future features.  Are we sure we'll
never want an omitted argument to mean something else, eg. "use the
defaults" or "splat the first two elements of the last parameter"?  Or that
it'll never create a grammar ambiguity with some construct we *do* want to
support?

I'm largely neutral on the feature itself.  Trailing commas have been
somewhat helpful when working with some large-scale codebases - they reduce
edit conflicts when adjacent lines are changed.  But I've also seen the
problem where a trailing comma was a function call that I forgot to
finish.  And my code is not noticeably worse for their lack - it's just an
extra 5 seconds or so to update the next line.

Probably my vote would be "defer", and let the other changes slated for
Swift 3 & 4 work there way out.  Then we could see how the language evolves
in syntax, and how big a problem this is in practice, and then add trailing
commas in a year or two if people still believe it's a good idea.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160310/a3057b32/attachment.html>


More information about the swift-evolution mailing list