Live data from Hacker News

What’s New in C# 7.0

blogs.msdn.microsoft.com

171–180 of 278 posts

Re: What’s New in C# 7.0

#171
post #168

I tend to avoid using switch/case for quite irrational reasons. The break statement just looks wrong and I can't layout the code in a way I find at all pleasing. I'll almost always use a sequence of else if conditions instead. In my ideal world, it'd look like... switch (x) { case 1: { /* ... */ } case 2: case 3: { /* ... */ } } And before anyone points it out, switch is the same as else if when the thing being compa…

Same here, plus I think the parent brakes are noise, can the compiler just know that the switch statement ends on last case?

Re: What’s New in C# 7.0

#172
post #167

Earlier quoted context omitted.

I find that the verbosity can be minimised by type aliasing. E.g: using Complex = System.Tuple ; Edit: Clarity

But then you might as well declare a class or structure to store the data. The point of tuples is to be self-contained.

It maybe wasn't clear, but I was referring to the parent's point about verbosity when using the 'old' Tuple class.

    using Complex = System.Tuple;
is less verbose than

    public class Complex
    {
        public double i { get; set; }
        public double j { get; set; }
    }

Re: What’s New in C# 7.0

#173

What's the point of GetCoordinates(out var x, out var y) over destructuring assignment like var x, var y = GetCoordinates(); the former looks completely backwards.

The former works with pre-tuple out-parameter-based API e.g. Int32.TryParse.

Re: What’s New in C# 7.0

#174

What's the point of GetCoordinates(out var x, out var y) over destructuring assignment like var x, var y = GetCoordinates(); the former looks completely backwards.

Maybe the former method would make more sense to use if it were HasCoordinates and returned a Boolean?

This way you would get a Boolean if the coordinates exist and would not have to perform validation on the out variables.

Re: What’s New in C# 7.0

#175
post #121

Having done a lot of python recently, this looks great (and familiar). But some things feel a little bit rushed: - In the example "(o is int i || (o is string s && int.TryParse(s, out i))": When reading this statement as a human, o is obviously not an int when it comes down to the TryParse function. But if the 1st part was removed, the 2nd part wouldn't be valid either. I know this is technically how declarations wor…

I was thrown by the first one you pointed out too, I'm still not sure I understand it.

The page said for type patterns it will "test that the input has type T, and if so, extracts the value of the input into a fresh variable x of type T", so if o is an int it'll be extracted to a fresh int i with that value

But the out syntax in TryParse isn't the new one they mentioned, it's the current one that requires predeclared variables - to be new it'd be out int i or out var i. So i is already declared as an int before this code example? In that case how can the first bit work? Does it not create a "fresh variable" if there's already one in scope with the desired name and type? That could be quite confusing, usual behavior is to compile error if an inner scoped variable conflicts with an outer one, I'm not sure I understand why this should be different.

Re: What’s New in C# 7.0

#177
post #168

I tend to avoid using switch/case for quite irrational reasons. The break statement just looks wrong and I can't layout the code in a way I find at all pleasing. I'll almost always use a sequence of else if conditions instead. In my ideal world, it'd look like... switch (x) { case 1: { /* ... */ } case 2: case 3: { /* ... */ } } And before anyone points it out, switch is the same as else if when the thing being compa…

But you can already do almost that, right?

    switch (x)
    {
        case 1:
        {
            /* ... */
        }
        break;
        case 2:
        case 3:
        {
            /* ... */
        }
        break;
    }

Re: What’s New in C# 7.0

#178

CSharp once again showing it is the best language in terms of features and improvements. Great job all round by the designers.

I'd say Swift is more or less in line with C# with regards to functionality. Many new features added to C# seem to already exist in Swift. Swift could use some async/await mechanism en sometimes it's a bit annoying to typecast simple types for calculations, but otherwise Swift is a really sweet language to work with.

Nonetheless C# is a nice language. I enjoy writing C# code, just as I enjoy writing Swift code.

Re: What’s New in C# 7.0

#179
post #125
post #97

Earlier quoted context omitted.

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…

> Between 1998 and 2000 VB6 was perfect, you could develop Windows GUI applications in a rapid manner Delphi was much better.

I miss Borland.

Re: What’s New in C# 7.0

#180
post #178

CSharp once again showing it is the best language in terms of features and improvements. Great job all round by the designers.

I'd say Swift is more or less in line with C# with regards to functionality. Many new features added to C# seem to already exist in Swift. Swift could use some async/await mechanism en sometimes it's a bit annoying to typecast simple types for calculations, but otherwise Swift is a really sweet language to work with. Nonetheless C# is a nice language. I enjoy writing C# code, just as I enjoy writing Swift code.

I'd disagree with you to be honest. Swift is still in it's infancy, and while it copied many of it's features from CSharp, it did so poorly and even now they continue to make breaking changes to their standard with each update.
Post reply on HN