I've used this feature in other languages, and I'd love to see it in Swift. It would be a significant boon to the ergonomics of declarative-style APIs, of which there are some good examples in @Michael_Ilseman's post. I use these types of APIs quite a bit and find that juggling commas around as changes are made is a constant nuisance, and they add a lot of noise to non-trivial lists.
I have a few suggestions that might help alleviate some of the concerns raised in the thread.
First, each list should be all or nothing on commas. imo, using a mix of commas and no commas is more harmful than helpful, and in cases where you're concerned about ambiguity, you can start inserting commas and the compiler will force you to use them correctly as it always has. Users who don't want to use the feature could also avoid unintentionally introducing it when leaving off a comma by accident.
We could also raise warnings or errors for cases that we deem to be problematic, forcing the use of commas or less ambiguous formatting. We might enforce that member access cannot start on its own line in an uncomma'd list:
// Invalid
let list = [
foo
bar
.baz(x)
]
// Valid
let list = [
foo
bar.baz(
x
)
]
Similarly, to address arithmetic ambiguities, we could say that infix operators cannot start on their own line.
// Invalid
let list = [
1
- 1
+ 1
]
// Valid
let list = [
1 -
1 +
1
]
This doesn't address the potential confusion around accidentally using the unary prefix versions of these operators. We could forbid starting a line with a unary prefix operator, but imo that's too great a limitation to be worth it.
// Still valid, producing a three-element list
let list = [
1
-1
+1
]
To be clear, these rules would only apply to uncomma'd lists. The syntax would continue to be valid wherever it's valid currently.
I feel that this strikes a nice balance between usability and potential misuse of the feature.