Mads on the Future of C# (6.0)

« Immutable & Isolated Types Likely in Future C# | Main | C# for Systems Programming »

December 10, 2013

Mads on the Future of C# (6.0)

Mads Torgersen, head program manager of C#, presented the “Future of C#” at the NDC London conference on Friday morning 12/6. Most of the “probable” new features announced moved C# to a more succinct, functional programming style.

  1. Import type members into namespace.
  2. Succinct syntax for primary constructors.
  3. Readonly properties
  4. Property expressions (property lambdas)
  5. Method expressions
  6. Parameter arrays for IEnumerable interfaces
  7. Succinct null checking
  8. Multiple return values
  9. Constructor type inference

Mads provided a code demonstration of each new feature with before and after illustrations of how the code would be implement today versus the future. The code example below is taken from the presentation.

Embedded image permalink

using System;
using System.Text;
using System.Threading.Task;
// import types into namespace
using System.Math;

// primary constructor
public class Point(int x, int y)
{
    // readonly property
    public int X { get; } = x;
    public int Y { get; } = y;

    // property expressions
    public double Dist => Sqrt( X * X, Y * Y );

    // method expressions
    public Point Move(int dx, int dy) => new Point(X + dx, Y + dy);
    
    // parameter arrays for IEnumerable
    public static Point Avg(params IEnumerable<Point> points)
    {
        // monadic null checking
        if (points?.FirstOrDefault()?.X ?? -1 )
    }

    public void GetCoordinates(out int x, out int y) { x = X; y = Y; }
}

class Program
{
    static void Main(string[] args)
    {
        var p = new Point(1, 5);

        // multiple return values
        p.GetCoordinates(out var x, out var y);
    }
}

// constructor type parameter inference - 
var t = new Tuple(1,2); // infers Tuple<T1, T2>

The multiple return values features appears very tentative as some in the audience would prefer better syntax support for tuples. Mads took additional questions from the audience. Structural typing is “on the radar.” Mads would like to “get rid of FXCop” being a post-build process and “build in code contracts” instead of requiring a IL-rewriting step.

Sources:

http://adamralph.com/2013/12/06/ndc-diary-day-3/
http://channel9.msdn.com/Forums/Coffeehouse/Mads-Torgersen--NDC-London--The-Future-of-C
https://twitter.com/randompunter
https://twitter.com/jchannon
http://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated

Comments

© 2015 - Wesner P. Moise, LLC. All rights reserved.

free web stats