(no title)
Metasyntactic | 2 years ago
You can see the entire history of the proposal there. To answer you specific question, we went with `..` because that's what the language already uses for the complimentary 'pattern matching deconstruction' form for collection patterns.
In other words, you can already say this today:
if (x is [var start, .. var middle, .. var end]) { ... }
So the construction compliment to that is: M([start, .. middle, end])
We very much want 'construction/deconstruction' to have this sort of parity, and we will be continuing to follow that principle with new features we are continuing to invest in.--
Now, if your next question is "why was .. picked for collection deconstruction?" the answer is "because we considered that the nicest syntax from the choices we considered". Syntax is often very subjective, and we often come up with numerous forms to consider (along with examining other languages to see what they've done). In this case, we simply preferred `..` over `...`. The extra dot didn't add anything for us, and we also felt like it might be an operator we might want to use in the future for other language features.
--
Finally, if you're interested in these sorts of questions/designs, def participate on github.com/dotnet/csharplang. We do all our design in the open over there, and are always interested in community perspectives on these sorts of things.
Thanks!
nmarinov|2 years ago
I've noticed that `...` is frequently used to denote that there's some code that's omitted. However with the spread operator being added (and being `...` in other languages) and "we also felt like it might be an operator we might want to use in the future for other language features" it's a bit confusing at a glance whether that's new syntax or just a shorthand. And it makes searching difficult.
I'm not sure what to replace it with, possibly a comment would be clearer: `/* code here */` or at least `/* ... */`.
P.S. Collection expressions are an awesome new addition!
eddtries|2 years ago
mgurlitz|2 years ago