Live data from Hacker News

What’s New in C# 7.0

blogs.msdn.microsoft.com

111–120 of 278 posts

Re: What’s New in C# 7.0

#111
post #106

Earlier quoted context omitted.

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 } });

I'm not convinced that gives you that much more over using a delegate.

Re: What’s New in C# 7.0

#112

Earlier quoted context omitted.

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

[deleted]

Re: What’s New in C# 7.0

#113

Earlier quoted context omitted.

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.

A tuple struct fills nearly zero of the real use cases for language level tuples. No pattern matching makes it sort of useless.

What about returning multiple values from a function without declaring a dedicated type? That is pretty useful.

Re: What’s New in C# 7.0

#114
post #32

Wow, lot's of great stuff! I especially like local functions, I'm all for breaking up complicated methods into several methods to simplify and clarify syntax... but it always felt weird that all those methods where on an class scope even though they only were relevant for that method. This resulted in many cases that those methods needed to be broken out into their own class... which is the way to go some times but f…

I mostly agree, but until now I just created private helper methods and went on with my life. If there are many of them, I put them into a #region. There are alot of cases where such helpers can be used from two separate locations and they also increase discoverability for other devs.

If you really wanted to, wasn't it already possible to create anonymous delegates/lambdas locally? The only improvement I see with local named methods are readable stacktraces.I have to admit, the mangled names are a major headache for me (and the stacktraces starting at lamda invocations, missing the 'original' stacktrace. I'm looking at you Parallel.Foreach!)

Re: What’s New in C# 7.0

#115
post #33
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…

Yeah, I think lots of uses of out in the .Net framework are from the early days and a little bit of a mistake. Since they can't remove them this is suppose to make them easier to work with. TryGetValue comes to mind, but I agree overall out variables always felt clunky

Although F# manages to convert all those TryGetXXX methods into tuple-returning transparently, so it can be done. Just off the top of my head, you could probably write an extension method to wrap the original into the new format pretty easily.

Re: What’s New in C# 7.0

#116

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.

Very glad to see tuples and pattern matching also. But allowing the tuples to be structs with mutable public fields seems off. Once a tuple is constructed it shouldn't be mutable IMO, unless I'm missing some important use cases?

Re: What’s New in C# 7.0

#117
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…

It does seem silly, considering that F# already uses _ as a "don't care" wildcard, and it's a pretty common pattern already in C# lambda-heavy code to use the underscore for the same idea.

Re: What’s New in C# 7.0

#118
post #97
post #42

Earlier quoted context omitted.

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

So true. Between 1998 and 2000 VB6 was perfect, you could develop Windows GUI applications in a rapid manner. The VB6 IDE, the Windows UI guideline, the VB6 API, everything was great. And PlanetSourceCode.com was what was later SourceForge and nowadays GitHub. When I read about Microsoft's vision for .Net in 1999 about applications running as a service over the internet (that was their original idea), I thought that…

VB.net development is not that different from VB6. It is a way more sophisticated language and therefore can do more complex things. But the basic things take pretty much the same syntax than they were in VB6.

Re: What’s New in C# 7.0

#119
post #94

Earlier quoted context omitted.

"Full" pattern matching, as one would expect from F# for example, wouldn't be something I could expect from C#. For example: type Tree = Empty | Node of 'a * Tree * Tree There is no way to express this directly in C#. Thus, I am "locked out" of a whole class of Pattern Matching that I would get with F#. But that doesn't mean that C#-style pattern matching (really, Is-patterns and a Type Switch) don't fall under the u…

> C#, is every bit a form of pattern matching as matching on a particular case of a union type. I'm afraid that is not the case, because in the current C# version, the compiler does nothing help you determine if you've matched all the possibilities. (it is not exhaustive) Exhaustiveness is important because it gives warning or an error to help you refactor and modify code without fear of breaking other code. Why enga…

Yes, and because of the lack of record and union types in C#, it's (probably) nigh-impossible to pull off exhaustive pattern matching. However, this is still pattern matching - you can define tuple patterns which decompose the data, much like you can in F#; just with some different syntax.

I agree with you that exhaustiveness is incredibly important, and I really hope that it can be done in C# some day. However, record and union types are also a piece of this puzzle.

Re: What’s New in C# 7.0

#120
post #19

Since C# is starting to look more like JavaScript (i.e. local functions) and vice versa (i.e. arrow aka lambda expressions). I'm going to throw my pocket change into a couple features I've been growing old hoping to see: 1. Regex expressions just like Regexp in JS: /^\s+$/.IsMatch(" "); // or Regex r = /^\s+$/; 2. DateTime expressions, similar to regex, something like: DateTime clockTowerLightning = #1955/11/12 10:04…

I'll take DateTime literals, for sure. But only if they require using ISO date format. A slight munge of omitting the timezone to mean 'system local timezone' would be fine too. My main objection is over the month/day confusion with other formats. Is that November, or December?

ISO-serialized datetimes are the only serialized datetimes. At least if you want to avoid painfulness. Similarly, UTC is good. If there's one thing I've learned, it's that, for my own sanity, datetimes should be localized and formatted at the last possible instant, just before a human has to see them, and kept in a consistent, canonical form at all other times.
Post reply on HN