-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split the features/patterns branch into two branches for subfeatures in/out C# 7 #10866
Comments
No!!! Please don't leave With all the experiments I've done so far with patterns, I've probably used |
I think it makes more sense to also postpone var patterns because without recursive patterns there ain't no real use for var patterns alone. Honestly, I think the team could deliver a more sophisticated value binding pattern overall, but shipping var patterns would close that case right away. :( |
@DavidArno Your feedback on the prototype that results from these changes will be helpful in our planning. |
@alrz A var pattern is useful as the last case of a switch statement. I'm not sure what you have in mind with a "value binding pattern". |
I'm not sure that my feedback will change from now. It's difficult to articulate the frustration and sadness I feel over the As someone who uses C# to write functional-orientated code, the experience is a difficult one. A lot of the time, I seem to fight the language, rather than working with it. So when I first came to this site and saw the list of features that potentially might make it into C# 7, I was extremely excited: tuples, records, pattern matching were all up there at the top of the list. These were exactly the sort of features that I wanted added to the language. Exciting times lay ahead. Since then, I've seen things steadily go downhill:
What we will likely get are:
C# 7 started out appearing to be a super exciting release: "C# gets functional". Now though it's appearing to be a complete "meh" release. I'm sure some (maybe even the majority) will be excited by the likely new features, but even the features that do interest me (tuples and local functions) are disappointingly poor implementations of what I'd really like to have seen. More and more devs are catching the "functional bug". In the .NET world, this normally means switching to F#. Whilst a great language, it's not without its problems, such as having nowhere near the level of tooling that C# devs enjoy. A few months ago, C# 7 looked like it could offer a great set of functional features too, giving people a choice. That dream is well and truly shattered now. Maybe C# 8 will deliver, but maybe it will prioritise other features I'm not interested in (eg Having said all of that, I am aware that the language team have a difficult balancing act to contend with. They have conflicting demands from the majority who want more of the same and a minority who want radically new features in order to stay with the language. If you meet the needs of the former, you risk failing to stem the tide of leavers. If you meet the needs of the latter group, you risk complaints from the majority that you are pandering to a minority and ignoring what most want. Also, I accept that my "excitement to disappointment" experience is entirely of my own making. You guys have been very clear all along that nothing is set in stone and I've ignored that all along at my own cost. I've tried to offer honest feedback. If it comes across as negative criticism, I can only apologise as that isn't my intention. |
@gafter In the current spec |
In that comment, you wrote
But there is no hint "below" as to what a constant-pattern is, or how the ambiguity would be resolved. |
@gafter I could be more specific. That's nothing new though, Swift uses this semantics so I suppose it wouldn't be a problem, unless you see something that I don't. switch(e) {
// x and y are constants as the current spec
case (x, y): break;
// x and y are new variables as the current spec (just `let` instead of `var`)
case (let x, let x): break;
// x and y are new variables (`let` distributes to each identifier pattern)
// -- short for the previous case
case let (x, y): break;
// this is not allowed due to the "value-binding patterns cannot be nested" rule
case let (let x, let y): break;
// so the following is perfectly fine,
// an identifier inside a value-binding pattern which introduces a variable
case let x: break;
} This wouldn't be restricted to tuples and works for any other recursive patterns in the spec. switch(e) {
case let Point(x, y): break;
// equivalent to
case Point(let x, let y): break;
case let Point { X: x, Y: y }: break;
// equivalent to
case Point { X: let x, Y: let y }: break;
} This is specifically consistent with let-statement as it is kind of a "value-binding pattern" so that wouldn't be much of a surprise and there is no need to special case let x = e;
let (x, y) = e; |
The production pattern
: `let` pattern
; doesn't makes sense to me. Is the idea that once you put |
This is now done. Part 1 is in |
@gafter Non-identifier constants are fine, but identifiers will be new variables in presence of You can't prevent the recursion syntactically, because you might have a let pattern anywhere inside it anyway. So it has to be done semantically. |
I would like to add that I've had my own libraries for "pattern matching" previously, but having the feature actually incorporated in the language results in far-higher quality code than any implementation I could think of using only existing features. It won't be that horrible to emulate with |
does this split have any implications for exhaustiveness checking in switch/match? |
No. |
If
That is so awkward that even nested ?: are better. Also, it can't be a subexpression.
This code is clean but tooling support is notoriously bad for that pattern. Can we not have a form of |
I'm pretty sure that |
I understand that and it's a cause for great sadness! Is the list below "What we will likely get are" in this thread exhaustive? That would be like C# 4 in significance which was the least significant release so far. |
The
features/patterns
branch needs to be split into two branches for those features we are reasonably certain will be in C# 7 and those features that might be delivered in a later release. The former can be integrated into thefuture
branch and the latter can remain in thepatterns/feature
branch.Part 1 (targeting
future
):expression is Type identifier
case Pattern when expression:
with the following pattern formsPart 2 (to remain in
features/patterns
):*
let
statementmatch
expressionthrow
expressionThe text was updated successfully, but these errors were encountered: