Live data from Hacker News

What’s New in C# 7.0

blogs.msdn.microsoft.com

101–110 of 278 posts

Re: What’s New in C# 7.0

#101

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.

Why not winforms? Very convenient, and mostly works in mono

Re: What’s New in C# 7.0

#102

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…

"WinForms" is "language tooling"? "XAML" is "language tooling"? By what definition? I can write server-side C# in vim (without omnisharp) just fine, actually. Maybe the tools became "indispensable" because they add value? I refactor my code in vim but it would probably be faster in VSCode. That doesn't make C# a bad language.

C# has (had? I'm still a couple of versions behind) so much syntactical overhead that writing code without a visual studio seems painful at the very least.

The var keyword was the first time it was even possible to write C# without tooling. It has definitely made it possible for me to use Vim for editing C# code. Newer features, such as lambda expressions, and some of the much nicer property syntax makes me feel that it may actually be fun to write C# from scratch without Visuak Studio looking over it.

Re: What’s New in C# 7.0

#103

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.

Can you give an example of how C# would be different with anonymous classes?

Googling that term just gives a whole lot of references to inner classes in Java.

Re: What’s New in C# 7.0

#104
post #90
post #66

Earlier quoted context omitted.

> 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 o…

Well maybe you don't care, but there are folks that do (I'm on that list) ;-) I want the speed of C but the safety of C#. There are many pieces of code that you probably use every day that go to great lengths to squeeze as much power as possible. Why not help these folks help us? I'm glad there is more focus on performance because we all benefit. (Hoping to see more on the CLR side.)

Why c# and not rust or something similar that has a lower level focus?

Re: What’s New in C# 7.0

#105
post #7

It looks like they've added a lot of rope to hang ourselves with typos. int myvar, I; foo(out int mvar); // oops, not myvar; maybe caused by a refactor? bar(out *); // oops, not I; was up too late coding And so on. Things like this would be easily missed when reading code at-a-glance, and it's this sort of bug that arises often in languages that allow implicit declaration of variants.

The first one requires 2 errors. Reinitializing a variable (if you intended to use myvar then you wouldn't need to put int after your out) and compounding it with a misspelling. This is no different from how you'd make the same mistake today.

I'm not happy about wild cards. It seems like taking what is a very powerful character in software development and using it for a pretty minor usability improvement. Besides it seems misleading. When I see an asterisk I don't think throwaway. I can see how that aligns with "anything can go here" meaning from regex, but I feel there is a difference in "value". Using a * in a regex seems to increase the power and heft of the regex, where as using it here, seems to decrease the value, which is almost the opposite effect. Another way of putting it is that the point should be to let me ignore this while reading code, but the asterisk draws my attention to it instead.

Compare this to the Haskell convention of using an _ for throwaway items, which disappears just enough, instead of attracting attention. And by simply being a convention, it isn't giving the character too much power.

Not sure if lack of Haskell style type inference prevents C# from using convention for throwaways instead of wildcard chars, but I think it would be much less overhead on the Dev.

Re: What’s New in C# 7.0

#106

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.

Can you give an example of how C# would be different with anonymous classes? Googling that term just gives a whole lot of references to inner classes in Java.

One I've come across is binding a command to a button. With anonymous inner classes you can have something like:

  myButton.AddListener(new Command {
    bool enabled() {
      return false; //more logic goes here
    }
    void onClick() {
      //do something
    }
  });

Re: What’s New in C# 7.0

#107

Earlier quoted context omitted.

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

Every language has something missing, but C# has plenty of other great features so tuples weren't really that big of a problem. There are also plenty of built-in containers like the Tuple class that can offer the same functionality.

Exactly. The biggest that comes to my mind is generics which are missing from many languages.

Re: What’s New in C# 7.0

#108
post #38

Earlier quoted context omitted.

There was always the Tuple class you could use since .Net 4. https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.1...

There's a few downsides to the Tuple class as mentioned here: https://github.com/dotnet/roslyn/issues/347 Namely, heap allocation and the inability to name tuple members.

And a very verbose syntax. You have to repeat everywhere the different types of the different members.

Re: What’s New in C# 7.0

#109
post #92

I thought pattern matching in C# would look like pattern matching in Elixir. For example, two functions with different signatures run based on the parameters you give it. def hello("sergio") do IO.puts "Hello Sergio" end def hello(name) do IO.puts "Hello #{name}" end --- hello("sergio") => "Hello Sergio" hello("mia") => "Hello mia"

Isn't that more an example of `multiple dispatch` rather than `pattern matching`?

Both :) You can pattern match in function head (definition)

http://elixir-lang.org/getting-started/pattern-matching.html

Re: What’s New in C# 7.0

#110
post #45

Earlier quoted context omitted.

Adding features for the the subset of developers that need optional performance enhancements is great. However, it does seem ripe for misuse. As in the developer who makes everything a ref reference because they read it makes it "faster." Would there be a way to get Visual Studio to warn about this?

Sure. Write a Roslyn analyzer to help out here. Note: it's not like you can just sprinkle 'ref' on the return type of your methods willy nilly. Like 'ref'/'out' parameters, it requires you to do very specific things to keep your code safe/legal. As such, it's unlikely to just be added by people because, by and large, most code won't be equipped to actually handle it properly. The codebases that will want to use this…

I think it's great that you guys are adding a lot of high performance features that are beneficial to game engines. Any news you can share with us on a certain very-popular-game-engine-running-a-very-old-version-of-the-clr? ;)
Post reply on HN