[swift-evolution] [Review] SE-0084: Allow trailing commas in parameter lists and tuples
laurent.mihalkovic at gmail.com
Thu May 12 12:31:11 CDT 2016
I find it symptomatic that the 'popular' languages where this is allowed all seem to be rooted in scripting++ rather than in hard core, strong grammar languages. But i guess the two shall at some point meet... in swift?!
Could the feature perhaps be reserved for SwiftScript 1.0 then, instead of added to Swift 3.0? The situation somehow reminds me of Martin Orderski's early decision to make XML a first class citizen in Scala to fish for more audience, and his recent about face and cleaning up of the grammar.
> On May 12, 2016, at 6:31 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
>>> On May 10, 2016, at 2:58 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>>> On May 10, 2016, at 12:36 PM, Tony Allevato <allevato at google.com> wrote:
>>> Likewise for function calls; I would argue that if a function call/definition's parameter list is likely to grow so much and/or so frequently that a trailing comma provides significant savings, that's a code smell that should encourage the author to redesign the function.
>> FWIW, I personally agree with this observation.
>> Parameter lists and tuples are also structurally different than collections. Parameter lists also have labels, and (depending on how the ‘disable reordering default arguments’ decision goes) parameters may not be added and reordered arbitrarily. Tuples are different because adding a member will often break all the code downstream because it changes the type of the value. This is different than array and dictionary literals.
>> The only “collection like” aspect I can think of is for variadic parameter lists, but I don’t think they’re common enough to provide a special case for.
> I agree that the trailing comma offers its best support for situations that express variadic properties. I propose that all three of the following scenarios share this nature:
> At call sites with variadic arguments
> At call sites with defaulted arguments
> At definition sites with large complex argument lists or tuple members
> It's slightly easier to make the case for call sites, the first two of these uses, as they exactly mirror the way collections parse members. Supporting the third style of trailing commas requires the consideration of real world modern Swift.
> Allowing cut and paste or commenting of entire parameter lines means simple changes do not ripple out to affect other lines. In this, trailing commas serve programmer intent and limit the effect in diff comparisons. As Joe pointed out in one of his responses on this thread, one edit becomes one diff, without extra housekeeping for other affected lines. When considered together, I do believe the use cases for these scenarios are common enough to be considered something other than a "special case".
> Given that SE-0060 is accepted, the third case is narrowed but should not be ignored. Reordering and commenting out lines during prototyping, working in playgrounds, and scripting is still common. Also, a reorder or comment when trailing commas are permitted ensures that such changes are single-point edits.
> As Brent points out in his review, "I was skeptical of this until a week or two ago, when I had some code where I ended up commenting out certain parameters." Trailing commas, although a minor feature in a major language, still serves the developer and supports the overall philosophy of Swift, which is as you have pointed out multiple times, an opinionated language.
> -- E
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution