[swift-evolution] Allowing trailing commas in argument lists

Rainer Brockerhoff rainer at brockerhoff.net
Thu Mar 10 17:23:30 CST 2016


On 3/10/16 17:27, Erica Sadun via swift-evolution wrote:
>>>> On 10 Mar 2016, at 17:28, Radosław Pietruszewski <radexpl at gmail.com <mailto:radexpl-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>> 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.

+1!

I became aware that trailing commas were now allowed in (Obj)C
relatively recently and use them exclusively now in lists of enums,
array and dictionary constants, and so forth.

Of course with a preprocessor they allow conditionally inserting
elements without any conditional gimcrackery or the hack of inserting a
final dummy element without a trailing comma.

Even so, optional trailing commas will no doubt be useful in Swift too.
I think specifically of commenting out (or uncommenting) elements during
debugging or exploratory programming.



> 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.

Excellent argument, too.

-- 
Rainer Brockerhoff  <rainer at brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://brockerhoff.net/blog/



More information about the swift-evolution mailing list