Trailing commas in all expression lists

I would like to have a unifying theory as part of the proposal to explain the rationale for allowing trailing commas in some places but not other. I don't think it is a goal to allow people to add trailing commas to any syntactic list that includes commas. The utility argument here is based around the goal of allowing more free evolution and iteration of code.

For example, I could see a consistent argument along the lines of:

"swift supports trailing commas in comma separated lists that are variable length, or where elements are optional"

Such a policy would admit commas for array and dictionary literals, function calls with varargs or defaulted arguments. You could argue one way or other other to allow trailing commas in non-varargs calls that don't have defaulted arguments, but the specific description above would not allow it.

Similarly, I don't see a rationale to allow trailing commas in generic type lists. You can't just drop a type from the list, so the top level argument doesn't matter.

16 Likes