Collection expressions - spread operator Symbol question #7686
-
I've learned about collection expressions feature from - https://devblogs.microsoft.com/dotnet/announcing-csharp-12/ While it seems nice addition to language I feel like syntax for spread operator is weird. "Looking at the surrounding ecosystem, we also find examples everywhere of list creation being more convenient and pleasant to use. TypeScript, Dart, Swift, Elm, Python, and more opt for a succinct syntax for this purpose, with widespread usage, and to great effect. Cursory investigations have revealed no substantive problems arising in those ecosystems with having these literals built in." While the concept is familiar, syntax seems unfamiliar. The first question that came to my mind - why not 3 dots like it's in JavaScript, Dart and even Java. I feel like using something familiar (for developers coming from other languages) would be a better design choice. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is covered in the design doc :) Specifically, we already use if (x is [var start, .. var middle, var end]) We also want construction and deconstruction to be mirrored. So the form that allows that is: M([start, .. middle, end]);
Syntax familiarity comes very quickly to developers.
We do consider that. And all other things being equal we might have landed there. But in this case, all other things were not equal. Strong parity in our own language def takes precedent. |
Beta Was this translation helpful? Give feedback.
This is covered in the design doc :)
Specifically, we already use
..
to represent a set of elements when deconstructing. Like so:We also want construction and deconstruction to be mirrored. So the form that allows that is:
Syntax familiarity comes very quickly to developers.
We do consider that. And all other things …