News

Microsoft Quickens C# Release Cadence, Unveils v7.1

In keeping with the general trend of releasing software versions more frequently, Microsoft is quickening the release cadence of its C# programming language, starting with the new C# 7.1.

As many .NET coders already know, C# 7.1 was actually released in August, but Microsoft yesterday chose to highlight the new version and review its new features in a post announcing the accelerated release schedule.

Mads Torgersen, lead designer for C#, said the team is moving to "point releases" to keep up with associated tooling -- like Visual Studio -- and the underlying .NET Framework itself that are shipped more frequently. This, he said, brings new features to developers in a trickle so they can take advantage of them sooner. With Visual Studio 2017 (update 15.3 is required for the new C# 7.1 functionality), developers can configure the IDE to incorporate minor x.x releases or stick only to major x.0 versions.

In C# 7.1, three new (admittedly minor) features are being called out by Microsoft for special attention in the release notes:

  • async Main method
    The traditional Main method that starts C# projects can now include the async modifier, which lets coders use the await keyword (actually introduced in C# 5.0). Converting Main into an async method lets it return Task or Task(int), causing a program to wait for the Task to execute.

    That, Torgersen said, does away with the need to roll your own helper method and lets developers turn this code:

    static void Main(string[] args) => MainAsync().GetAwaiter().GetResult();

    into:
    static async Task Main(string[] args)

  • Default literal expressions
    Developers can use default literal expressions in default value expressions in those cases when the target type can be inferred. This enhancement means developers no longer need to specifically indicate the type on the right-hand side of an expression initialization, turning code like this:

    Func<string, bool> whereClause = default(Func<string, bool>);

    into:

    Func<string, bool> whereClause = default;


  • Inferred tuple element names
    This feature just streamlines the initialization of tuples, themselves only recently supported in C#. Noting that "many times when you initialize a tuple, the variables used for the right side of the assignment are the same as the names you'd like for the tuple elements," Microsoft said the feature can turn code like this:

    int count = 5;
    string label = "Colors used in the map";
    var pair = (count: count, label: label);

    into:

    int count = 5;
    string label = "Colors used in the map";
    var pair = (count, label); // element names are "count" and "label"

While these features can save developers some coding time and ease repetitive typing, one programmer commenting on Torgersen's post objected to the injection of more implicit features -- often called "syntactic sugar." The reader said:

Please ease up on implied constructs such as the inferred tuple element names. These new implicit features will only increase ramp-up times and make things more complicated.

Yes, you can just opt not to use them, but trying to stop people from using language features is a lost cause. Too much sugar can make you sick, and likewise too much syntactic sugar can make a codebase very unhealthy to read.

Here is Torgersen's response to that:

Indeed, too much sugar can make you sick. We try to add it where we have high confidence that it will make your code better. In this case, we knew that the shorthand would be useful -- we've already had it for anonymous types since C# 3.0.

In general, the language has to grow with usage. A sharp corner that people have to turn all the time? We should probably round it! We have to not be afraid to make common tasks easier. But at the same time I completely agree with you that there are dangers of making code to cryptic, with too many things being too implicit. It's a tradeoff.

Torgersen said his team is already working on C# 7.2 as well as the next major release, inviting developers to follow the progress on the project's C# Language Design GitHub site.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • Full Stack Hands-On Development with .NET

    In the fast-paced realm of modern software development, proficiency across a full stack of technologies is not just beneficial, it's essential. Microsoft has an entire stack of open source development components in its .NET platform (formerly known as .NET Core) that can be used to build an end-to-end set of applications.

  • .NET-Centric Uno Platform Debuts 'Single Project' for 9 Targets

    "We've reduced the complexity of project files and eliminated the need for explicit NuGet package references, separate project libraries, or 'shared' projects."

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

Subscribe on YouTube