<div dir="ltr">+1, I don't remember ever making a mistake (in a trailing-comma-allowing language) that would have been caught if trailing commas had been considered an error. But I do remember editing commas a lot in languages in which trailing commas are considered an error.<div><br></div><div>(I would also be in favor of whitespace-separated elements (instead of the current comma+optionalButAlmostAlwaysInPracticeWhitespace-separated elements), but I'm 99% sure that would never be accepted by the community.)</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 9, 2016 at 1:54 PM, Nisse Bergman via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-1<br>
Let’s not go down this path and enable the javascript flamewar of trailing or non-trailing commas.<br>
<br>
Nisse<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
> On 09 Mar 2016, at 01:23, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Yes please.<br>
><br>
>> On Mar 8, 2016, at 2:07 PM, Grant Paul via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>><br>
>> ## Introduction<br>
>><br>
>> Right now, Swift argument lists are not permitted to contain trailing commas. To make multi-line calls easier, we propose allowing trailing commas in argument (and tuple) syntax:<br>
>><br>
>> let person = Person(<br>
>> id: json['id'],<br>
>> name: json['name'],<br>
>> picture: Im2age(picture),<br>
>> friends: friends,<br>
>> )<br>
>><br>
>><br>
>> ## Motivation<br>
>><br>
>> It’s common for functions to take a number of arguments. In some languages, this can make it difficult to figure out what a function does, leading to patterns like fluent interfaces and configuration objects.<br>
>><br>
>> Swift, by contrast, handles this very well. Argument labels make sure parameters aren’t confused even when they’re of the same type. And compared to Objective-C, it’s much easier to write a multi-line list of arguments in Swift.<br>
>><br>
>> However, with a parentheses placement style placing the closing parentheses for a multi-line call on a new line, Swift does not support a trailing comma. Trailing commas have a number of benefits:<br>
>><br>
>> - It is easier to re-arrange lines (especially in certain text editors) when all lines have commas.<br>
>> - Line-based diffs (as used by most source control systems) only show added lines when adding a new parameter to the end, rather than two lines where one just adds the comma.<br>
>> - It’s more consistent with other Swift lists which do support trailing commas.<br>
>><br>
>><br>
>> ## Proposed Solution<br>
>><br>
>> The proposed solution is to allow and ignore trailing commas in argument lists and tuples:<br>
>><br>
>> let person = Person(<br>
>> id: json['id'],<br>
>> name: json['name'],<br>
>> picture: Image(picture),<br>
>> friends: friends,<br>
>> )<br>
>><br>
>> let tuple = (<br>
>> color,<br>
>> 32,<br>
>> )<br>
>><br>
>><br>
>> ## Detailed Design<br>
>><br>
>> Support for trailing commas in argument lists and tuples would make them consistent with Swift’s handling of array literals, which do support trailing commas:<br>
>><br>
>> let array = [<br>
>> 2,<br>
>> 4,<br>
>> 8,<br>
>> ]<br>
>><br>
>> There should not be any impact to existing code from this proposal.<br>
>><br>
>> Support for this syntax is also found in other programming languages like Python, D, and Hack. It’s been proposed for JavaScript (positive response) and PHP (rejected):<br>
>><br>
>> - JavaScript: <a href="https://jeffmo.github.io/es-trailing-function-commas/" rel="noreferrer" target="_blank">https://jeffmo.github.io/es-trailing-function-commas/</a><br>
>> - PHP: <a href="https://wiki.php.net/rfc/trailing-comma-function-args" rel="noreferrer" target="_blank">https://wiki.php.net/rfc/trailing-comma-function-args</a><br>
>><br>
>><br>
>> ## Alternatives Considered<br>
>><br>
>> The main alternative is the existing behavior. This has the benefit of standardizing Swift code on a particular style. However, many people will in practice continue to use a style regardless of support trailing commas, especially for cross-language consistency. It could also lead to JavaScript-inspired parameter ordering:<br>
>><br>
>> let person =<br>
>> Person(id: json['id']<br>
>> , name: json['name']<br>
>> , picture: Image(picture)<br>
>> , friends: friends)<br>
>><br>
>> Another alternative would be to support this syntax for function parameters but not tuples. However, this would be an arbitrary inconsistency.<br>
>><br>
>> _______________________________________________<br>
>> swift-evolution mailing list<br>
>> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
>> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden<br><a href="http://www.bitcycle.com/" target="_blank">http://www.bitcycle.com/</a><br>Phone: +46-73-753 24 62<br>E-mail: <a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a><br><br></div>
</div>