Git Product home page Git Product logo

Comments (16)

DavidArno avatar DavidArno commented on July 17, 2024 10

@HaloFour,

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.

DavidArno avatar DavidArno commented on July 17, 2024 5

Sad to see this slip, yet again, from 7.1 to post 7.2. Please can we have it soon.

from csharplang.

alrz avatar alrz commented on July 17, 2024 2

didn't see that coming. http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html

from csharplang.

HaloFour avatar HaloFour commented on July 17, 2024 2

@alrz

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.

@DavidArno

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.

alrz avatar alrz commented on July 17, 2024 1

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.

alrz avatar alrz commented on July 17, 2024 1

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.

gordanr avatar gordanr commented on July 17, 2024

@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.

alrz avatar alrz commented on July 17, 2024

@gordanr Filed issue: #246.

from csharplang.

DavidArno avatar DavidArno commented on July 17, 2024

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.

orthoxerox avatar orthoxerox commented on July 17, 2024

@alrz The other 20% users probably account for 80% of MSFT's DevDiv revenue.

from csharplang.

alrz avatar alrz commented on July 17, 2024

@orthoxerox C++ also did this for auto. C# does not have a bigger audience than those languages.

from csharplang.

HaloFour avatar HaloFour commented on July 17, 2024

@alrz

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.

gafter avatar gafter commented on July 17, 2024

A prototype of the latest pattern-matching stuff is available at https://github.com/dotnet/csharplang/wiki/vNext-Preview

from csharplang.

philn5d avatar philn5d commented on July 17, 2024

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.

HaloFour avatar HaloFour commented on July 17, 2024

@philn5d

As you're suggesting new syntax I would suggest opening a new issue.

from csharplang.

munael avatar munael commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.