Why did Swift adopt the use of commas?

Me too, but I strongly suspect it's just because commas are what I'm used to. Most Lisp languages don't use commas [like this], and I've used Scheme a little myself and don't recall any issues with the "lack" of commas.

There are certainly cases - like with semicolons - where the meaning is ambiguous without an explicit separator. See previous proposals and discussions on eliding commas. As a quick example;

foo(
    bar
    .baz
)

Does that mean:

foo(bar.baz)

…or:

foo(bar, .baz)

It's certainly solvable (e.g. have an arbitrary rule as to which it means, or require a comma in ambiguous cases like that), but it does show you can't avoid commas entirely.

As to why Swift uses commas, I know this question has been asked before and I've never seen any kind of authoritative answer. I suspect that's the answer in itself - probably the earliest Swift contributors just never questioned the use of commas (coming, as they were, from C/C++/Objective-C where commas are all present and used the same) or didn't feel it was an interesting question to consider [relative to the many other important decisions that had to be made early on].

2 Likes