Thursday at Windows Build Anders Hejlsberg presented the future directions of C#. The new version number of C# is 5. The major features on this version are the integration of the Windows Runtime (WinRT) and of course the already well known async and await keywords for asynchronous programming. Anders also talked about some other cool features that I’ll introduce here.
Async Programming
The preview of the async features for C# v5 are out for some time now. I’ve already shown these keywords in a blog article from last year. Deeper information on this will follow in upcoming blog articles. Anders also talked about some other cool features that I’ll introduce here.
Great news at the conference is that the WinRT API offers async versions of the API if the function needs more than 15ms. This are 10-15% of the methods of the API. These APIs only offer async versions. Functionality like file I/O, network I/O…
And async methods have a big place in the .NET Framework as well. This makes it a lot easier to write async applications. And all applications should use this! The user interface must be very very responsive.
WinRT API asynchronous methods use IAsyncOperation<T>, .NET methods Task<T>, and JavaScript promises.
Windows Runtime
The Windows Runtime is written natively. It’s a new version of COM. Using namespaces, classes, constructors, statics, events… Using it from C# feels very natural. Although it’s implemented natively it nearly cannot be differentiated from C# calling into managed methods. The Windows Runtime team took a lot of features from .NET and added it to the native Windows API.
It’s similar easy to create C# types that can be used from any language making use of WinRT, e.g. JavaScript. Interop is made easy, no longer [DllImport] and COM Interop attributes. Just create a public C# type that is sealed and restricted to the types of the WinRT (or types that are mapped automatically like collection interface types). The method GetMovies() returning IAsyncOperation<IList<Movie>> can be called directly from JavaScript. For Task<T> can be easily converted to IAsyncOperation<T>.
Caller Info Attributes
C++ allows changing the code line numbers and filenames with __LINE__ and __FILE__ macros. Macros are not possible in C# and never will be. However, this feature now made it into C# by using optional parameters. The attributes CallerFilePath, CallerLineNumber, and CallerMembername can be used with optional parameters. Thus it’s easy to change the line numbers like in C++ but without Macros.
Compiler as a Service – Codename Roslyn
Looking more into the future of C#, Anders introduced the current state of compiler as a service. Scenarios that are possible with this are meta-programming, read-eval-print loops, DSL embedding, accessing the complete language object model…
Anders showed how to copy C# code and paste it as Visual Basic, and the other way around. Refactoring a data class by implementing INotifyPropertyChanged to extend the properties automatically. A C# interactive Window where code can be added on the fly including intellisense and refactoring features.
I think this to be a big changer in the features available within Visual Studio and expect a lot of extensions not only from Microsoft but also coming from the community.
A CTP will be available In four weeks from now.
Summary
To summarize the most important parts: C# deeply supports the Windows Runtime, makes async programming really easy, hybrid C#/JavaScript applications are easy to do, and a CTP for Roslyn will be available soon.
Christian
great blog! Thank you for raising this question! Our standards in MA require state sites to work without Javascript, but it’s getting harder to defend for web-based applications. Accessible Javascript is much more usable-for everybody-than the unenhanced HTML in more and more situations.
Posted by: property website design | 04/17/2012 at 08:46 PM