Live data from Hacker News

What’s New in C# 7.0

blogs.msdn.microsoft.com

61–70 of 278 posts

Re: What’s New in C# 7.0

#61

Does the pattern matching also statically check that you don't try to use a failed match. What if instead of if (o is null) return; // constant pattern "null" if (!(o is int i)) return; // type pattern "int i" WriteLine(new string('*', i)); somone forgot to return, as in if (!(o is int i)) { // do something } // incorrectly try to use `o` as an int WriteLine(new string('*', i)); Rust uses the special `match` syntax t…

My guess is this would be covered by the "have you initialised the variable" check, similarly to:

    int i;
    if (x == 3) { i = 2; }
    WriteLine(i);
I'd be interested to hear the answer, though.

Re: What’s New in C# 7.0

#62

Unfortunately, C# can flail about adopting F# features yet the best feature of F# is something C# can never get: Dependency Order Compilation

Hi David, language designer here. Can you give an example of where you'd want to take advantage of this in C#? Thanks!

I don't understand the question, rather what's the point of it?

Re: What’s New in C# 7.0

#66
post #2

Out variables seem like a mis-feature, especially when they are adding a better alternative (Tuples) in the same release. It's great to finally have tuples, but the c/java style syntax is showing it's age compared to something like scala which has return type declarations at the end, which I find much more readable. Literal improvements will be a godsend for writing database migrations. Ref returns and locals look li…

Hey there, C# language designer here. > Out variables seem like a mis-feature, especially when they are adding a better alternative (Tuples) in the same release. Out variables are really great when working with existing code that predates Tuples (for example, the entire BCL). We don't just introduce language features that will only work well for new code. We also want to make the experience of coding against existing…

> That 'headache' has to be weighed against the needs of some parties to write very fast code and to have as little overhead as possible. ref returns enables a much more pleasant coding experience that enables these sorts of speedups in these specialized scenarios.

I'm worried this could result in a loss of focus, you can't make everyone happy all the time. c# is a fantastic language to develop applications in (web or desktop) but it's never going to be the fastest language around or be a systems level language. For me some of the other features listed here (like immutable records) would be a much better fit for where c# excels already.

Re: What’s New in C# 7.0

#67

Since we're all chipping in with features we'd like to see in C#, here are mine: anonymous classes - with actual class bodies, that can implement interfaces - and traits.

Yeah, coming from Java a decade ago this was the first thing I noticed lacking. And with all the stuff C# has introduced beyond that, I'm always fairly surprised that this hasn't been done.

In preparation, the feature currently called "anonymous classes" in C# needs to be redubbed "anonymous records". And in preparation for that, well, "nonymous" records need to be introduced.

Re: What’s New in C# 7.0

#68

Does the pattern matching also statically check that you don't try to use a failed match. What if instead of if (o is null) return; // constant pattern "null" if (!(o is int i)) return; // type pattern "int i" WriteLine(new string('*', i)); somone forgot to return, as in if (!(o is int i)) { // do something } // incorrectly try to use `o` as an int WriteLine(new string('*', i)); Rust uses the special `match` syntax t…

This was a concern of mine as well, as you can see in the discussion of scope changes for pattern variables [1], the C# checks for definite assignments handle this. So:

    if (o is int i) { f(i); }
    use_int(i); // 
But then if you have:

    if (o is int i || (o is string s and int.TryParse(out i)) use_int(i);
We know that `i` is definitely assigned at that location.

[1]: https://github.com/dotnet/roslyn/issues/12597

Re: What’s New in C# 7.0

#69
post #42

Sometimes it feels like we're entering a new age of coding. C# is so full of "features" that code refactoring tools like ReSharper, CodeRush and JustCode became simply indispensable. It is quite hard to be sure, every time, what is the most elegant/compact way of doing things. In the .Net/VisualStudio world, the language tooling (Intelisense, visual drawing XAML & WinForms, etc) became as important as the language se…

The most productive I've been as a developer was 20 years ago when I was creating VB6 apps and components...

You mean back when you could type a whole ten characters without twenty new languages and frameworks coming out showing you how obsolete you were? How lame!

Re: What’s New in C# 7.0

#70

Pattern matching! Tuples! Awesome, C# 7.0 is scratching two itches I've felt every time I've worked with it. If only .NET had a suitable cross-platform UI toolkit, then I'd be using it everywhere. Eto.Forms is a good attempt but I found rather buggy and limited at this point in development. Avalonia, while further along in terms of stability and features, doesn't even try to fit in with any platform's look and feel.

Feels kinda crazy to see tuples and pattern matching "just arrive" when other languages have had them for years.

Sure. Like how streams "just arrived" in Java yet C# has had the equivalent for years.

No language has every feature. C# is making enormous strides ahead of many of its counterparts.

Post reply on HN