<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">JavaScript’s common convention (and weird looking!) to use leading<br class="">commas is exactly because it can’t do trailing commas.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The reason I've seen for leading commas is that to add a new element to</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">the end of a list, you only need to change one line instead of two.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Well, yeah — that’s exactly why enabling (or… not banning?) trailing commas is nice. You can easily add new lines, reorder them, etc., and you don’t have to worry about the last line.</div><div><br class=""></div><div>The difference is, leading commas don’t require any special support, but I think most people would agree, a trailing comma is much more natural looking.</div><div><br class=""></div><div>— Radek</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Swift already allows trailing commas in arrays. Even if not everyone<br class="">will know or use this, I see zero harm in allowing trailing commas in<br class="">argument lists and tuples.<br class=""><br class="">+1. Because Why Not™.<br class=""><br class="">— Radek<br class=""><br class=""><blockquote type="cite" class="">On 09 Mar 2016, at 13:54, Nisse Bergman via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">-1<br class="">Let’s not go down this path and enable the javascript flamewar of trailing or non-trailing commas.<span class="Apple-converted-space">&nbsp;</span><br class=""><br class="">Nisse<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 09 Mar 2016, at 01:23, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">Yes please.<br class=""><br class=""><blockquote type="cite" class="">On Mar 8, 2016, at 2:07 PM, Grant Paul via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">## Introduction<br class=""><br class="">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 class=""><br class="">let person = Person(<br class="">&nbsp;&nbsp;&nbsp;id: json['id'],<br class="">&nbsp;&nbsp;&nbsp;name: json['name'],<br class="">&nbsp;&nbsp;&nbsp;picture: Im2age(picture),<br class="">&nbsp;&nbsp;&nbsp;friends: friends,<br class="">)<br class=""><br class=""><br class="">## Motivation<br class=""><br class="">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 class=""><br class="">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 class=""><br class="">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 class=""><br class="">- It is easier to re-arrange lines (especially in certain text editors) when all lines have commas.<span class="Apple-converted-space">&nbsp;</span><br class="">- 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 class="">- It’s more consistent with other Swift lists which do support trailing commas.<br class=""><br class=""><br class="">## Proposed Solution<br class=""><br class="">The proposed solution is to allow and ignore trailing commas in argument lists and tuples:<br class=""><br class="">let person = Person(<br class="">&nbsp;&nbsp;&nbsp;&nbsp;id: json['id'],<br class="">&nbsp;&nbsp;&nbsp;&nbsp;name: json['name'],<br class="">&nbsp;&nbsp;&nbsp;&nbsp;picture: Image(picture),<br class="">&nbsp;&nbsp;&nbsp;&nbsp;friends: friends,<br class="">)<br class=""><br class="">let tuple = (<br class="">&nbsp;&nbsp;&nbsp;color,<br class="">&nbsp;&nbsp;&nbsp;32,<br class="">)<br class=""><br class=""><br class="">## Detailed Design<br class=""><br class="">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 class=""><br class="">let array = [<br class="">&nbsp;&nbsp;&nbsp;&nbsp;2,<br class="">&nbsp;&nbsp;&nbsp;&nbsp;4,<br class="">&nbsp;&nbsp;&nbsp;&nbsp;8,<br class="">]<br class=""><br class="">There should not be any impact to existing code from this proposal.<br class=""><br class="">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 class=""><br class="">- JavaScript: <a href="https://jeffmo.github.io/es-trailing-function-commas/" class="">https://jeffmo.github.io/es-trailing-function-commas/</a><br class="">- PHP: <a href="https://wiki.php.net/rfc/trailing-comma-function-args" class="">https://wiki.php.net/rfc/trailing-comma-function-args</a><br class=""><br class=""><br class="">## Alternatives Considered<br class=""><br class="">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 class=""><br class="">let person =<br class="">&nbsp;&nbsp;&nbsp;&nbsp;Person(id: json['id']<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, name: json['name']<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, picture: Image(picture)<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, friends: friends)<br class=""><br class="">Another alternative would be to support this syntax for function parameters but not tuples. However, this would be an arbitrary inconsistency.<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space">&nbsp;</span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-Dave</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>