Live data from Hacker News

What’s New in C# 7.0

blogs.msdn.microsoft.com

11–20 of 278 posts

Re: What’s New in C# 7.0

#11
Like everything except "Ref returns and locals".

I don't think I've ever seen a case where I wished for that feature.

All the other things - tuples, anonymous out vars, pattern matching - I've found myself wanting quite often.

Re: What’s New in C# 7.0

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

> Literal improvements will be a godsend for writing database migrations.

Can you elaborate on this; both how it helps and why you're using C# for database migrations?

Re: What’s New in C# 7.0

#13

Like everything except "Ref returns and locals". I don't think I've ever seen a case where I wished for that feature. All the other things - tuples, anonymous out vars, pattern matching - I've found myself wanting quite often.

I believe ref returns are a performance feature. They seem a bit like move constructors in C++ in that they can save you a copy? But I am not confident I understand the nuances of move constructors to compare them properly.

Re: What’s New in C# 7.0

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

Out parameters are also useful in constructors. I often use them as a way to limit the scope in which an object can be modified, which lets me have mostly immutable objects.

    IEnumerable GetStudents(SqlCommand cmd)
    {
        var rdr = cmd.ExecuteReader(); //select * from student left join courses on...

        var memo = new Dictionary(); //Completion lets us add courses to a student

        while(rdr.Read())
        {        
            if(!memo.TryGetValue(rdr.GetInt32("student_id"), var out complete)
                 memo.Add(new Student(rdr out complete).ID, complete);

            complete.AddCourse(rdr); //might be a no-op
        }

        return from kv in memo select kv.Value.Student; //each student object is unmodifiable.
    }

Re: What’s New in C# 7.0

#15
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 semantics or the availability of frameworks and documentation.

A long ago there was a fad, known as CASE (Computer Aided Software Engineering) that advocated doing on programming what CAD did to other engineering. It seems that were finally getting there.

Re: What’s New in C# 7.0

#16
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.

R# should warn "unused variable myvar" on the first one. You'll get a compiler error if you try and use `I` uninitialized. Not saying you're wrong, just having trouble getting worried about this. You can make typos now: int x, y; foo(out x, out x); // oops, not y; was up too late coding

In a non-trivial example it's likely that `myvar` or `I` would see themselves used elsewhere, perhaps even as an out value to another method, and so raise no warnings. The source of the problem won't be so obvious at-a-glance because the new declaration syntax aren't so different from existing syntax, and could easily go unnoticed when shadowing existing values deep within a function.

Sure, you can make typos now, but these changes expand the possibilities of errors arising from typos or incomplete refactoring; while reducing the discoverability of the issue at-a-glance.

Re: What’s New in C# 7.0

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

> Literal improvements will be a godsend for writing database migrations. Can you elaborate on this; both how it helps and why you're using C# for database migrations?

My go to migrator is fluent migrator (https://github.com/schambers/fluentmigrator) or flywaydb if anyone objects to the c# (https://flywaydb.org/).

Each migration gets a number, typically time encoded. If I was to write one now it would have the attribute [Migration(201608251157)]. With the new literals this will become [Migration(20160825_1157)], amazing how much readability a single underscore can make.

Re: What’s New in C# 7.0

#18
post #8
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…

> it's age compared to something like scala which has return type declarations at the end, which I find much more readable. Scala or .... VB.net!

I'll begrudgingly admit it got a couple of things right.

Re: What’s New in C# 7.0

#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:04PM#;

Re: What’s New in C# 7.0

#20
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.

> foo(out int mvar); // oops, not myvar; maybe caused by a refactor?

This should fail to compile, it's the equivalent of declaring a variable twice int the same scope.

Post reply on HN