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 at Converge 360.

comments powered by Disqus

Featured

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events