Comments (16)
I have now stuck a postit note to my monitor that says, in big bold letters, "STOP MOANING ABOUT INTERFACES; YOU ARE BORING EVERYONE". Let's see if I can follow its advice...
from csharplang.
Sad to see this slip, yet again, from 7.1 to post 7.2. Please can we have it soon.
from csharplang.
didn't see that coming. http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
from csharplang.
I did. Java 8 made it a warning to use _
as an identifier. In Java 9 it's illegal. I totally expected that to open the path to wildcards in patterns.
The C# team could push proper pattern matching out to C# 11 and they'd still likely beat Java to the punch. But I expect that the C# team can actually work through interfaces and patterns at the same time, especially since a lot of the groundwork for the latter has been laid and a lot of the work of the former relies on an external team.
It'll be interesting to see where Java goes with the open questions, particularly since they recognize the same scoping issues that the C# team had to work through.
from csharplang.
Java 8 made it a warning to use _ as an identifier.
Thank god they do not do fallback-binding thingy. I wonder why C# is reluctant to take such changes. var should've been a keyword by now. I'd prefer warning-waves cripple my build rather than being another compiler flag. That's another example of how C# deals with these changes in a non-breaking way and it does no good for the remaining +80% of users who do not suck.
from csharplang.
It's moved to https://github.com/dotnet/csharplang/tree/master/proposals/csharp-8.0 as the feature is marked for the release.
from csharplang.
@alrz You have very nice, simple and powerful proposal in Roslyn repository.
Proposal: Negative Pattern #16766.
Maybe you could reopen that theme here.
from csharplang.
from csharplang.
Since I can see the implementation of the other 80% of pattern matching in C# slipping out to beyond v8 (due to the team being so focused on "improving" interfaces at the moment), it wouldn't surprise me if Java gets this stuff before C# does. 😞
from csharplang.
@alrz The other 20% users probably account for 80% of MSFT's DevDiv revenue.
from csharplang.
@orthoxerox C++ also did this for auto
. C# does not have a bigger audience than those languages.
from csharplang.
It's not the first time that Java has broken compatibility. When Java adds a keyword it's not done contextually. It's pretty rare when it happens. I think the last time was Java 5 and assert
.
Java 9 will be an interesting experiment. They've been pretty open that this release will potentially break a lot of code, for two major reasons. First, modules, which finally bring a degree of non-visibility to public/protected members, even through reflection. Second, they're finally going to finally remove a bunch of APIs that have been marked deprecated for a very long time. The removal of _
as a valid identifier is peanuts in comparison.
If the pain proves to be too much I could see Oracle pulling their punches going forward, perhaps even regressing a bit in a point release.
from csharplang.
A prototype of the latest pattern-matching stuff is available at https://github.com/dotnet/csharplang/wiki/vNext-Preview
from csharplang.
I looked for quite some time where to comment and landed here.
Related to this:
https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md
Which I believe is related to "Recursive Pattern" in this msdn blog post about C#8:
https://blogs.msdn.microsoft.com/dotnet/2018/11/12/building-c-8-0/
Which shows the following example:
IEnumerable<string> GetEnrollees()
{
foreach (var p in People)
{
if (p is Student { Graduated: false, Name: string name }) yield return name;
}
}
Wouldn't it be much more concise to allow:
IEnumerable<string> GetEnrollees()
{
foreach (Student { Graduated: false, Name: string name } in People)
{
yield return name;
}
}
and even:
IEnumerable<string> GetEnrollees()
{
foreach (Student { Graduated: false } as student in People)
{
yield return student;
}
}
In both cases, only People of type Student with property Graduated == false should be selected. In the first example, Name should also not be null.
In the first example, Name should be assigned to a string variable name
.
In the second example, the current Student instance should be assigned to the variable student
. The "as" keyword indicates the assignment.
It should be possible to combine as follows:
IEnumerable<string> GetEnrollees()
{
foreach (Student { Graduated: false, Name string name, StartDate DateTime startDate } as student in People)
{
if(CheckName(name) && startDate < today) yield return student;
}
}
from csharplang.
As you're suggesting new syntax I would suggest opening a new issue.
from csharplang.
@HaloFour , https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md is a 404.
As it stands, it's not really clear what syntax this issue is tracking.
There's a trail of public and LDM discussion history but they mention different parts of things related to pattern matching. It's just not clear what the current idea is.
from csharplang.
Related Issues (20)
- [Proposal]: First-Class Span Types HOT 30
- [Proposal]: Collection Expressions Next (C#13 and beyond) HOT 47
- Open issues: Breaking changes HOT 29
- [Proposal]: Field and value as contextual keywords HOT 33
- [Proposal]: Extended identifier syntax
- [API Proposal]: IsNullableAttribute to flow nullability of generic type parameters into methods HOT 4
- Anonymous type optimization HOT 5
- Feature Request: Recursively Foreach
- [Proposal]: Relax `Add` requirement for collection expression conversions to types implementing `IEnumerable` HOT 2
- [Proposal]: Proposal for Allowing Single-Element Tuples in Type Definitions HOT 2
- [Proposal]: Params collections and older language versions HOT 1
- [Proposal]: Edit speclets to distinguish features already delivered from potential future enhancements HOT 3
- [Proposal]: `readonly` parameters in primary constructors for non-record types HOT 7
- [Issue]: Generic Type Specialization Not Working in C# HOT 38
- [Proposal]: AAAAAAAAAAAAAAAAAAAA
- Open questions for `field` and `value` as contextual keywords HOT 2
- Add collection literal support for `Memory<T>` and `ReadOnlyMemory<T>`. HOT 18
- Unexpected compiler behavior with records and implicit operators HOT 1
- YaoJunFeng
- Invalid implicit conversion from long to int HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csharplang.