Microsoft's Roslyn invites VB to Windows 8 party

C# in disguise?

Secure remote control for conventional and virtual desktops

At Microsoft's recent BUILD conference, technical fellow and C# creator Anders Hejlsberg presented a session on the future of C# and Visual Basic. Visual Basic? There were few VB developers evident at BUILD and it seems to be in decline among professionals. Nevertheless, Microsoft is keeping the two in parity: read on for why the difference between them is becoming smaller.

The Hejlsberg talk was not all new. The two big features he presented – asynchrony and compiler as a service – have both been presented before. That said, the asynchronous features in C# 5.0 are more significant now that Microsoft has shown its new Windows Runtime (WinRT), with which it hopes to compete in the tablet market. Around 15 per cent of the APIs in WinRT are asynchronous, with no alternative provided. The idea is to force developers to build apps with responsive user interfaces.

Concurrent programming in C# was in the language from version 1.0. The effort since then has been to make it more efficient and easier to code, especially since mistakes can introduce subtle bugs. C# 4.0 introduced the Task Parallel Library, an abstraction that simplifies coding to some extent, but the new async features are even easier, especially when used with existing APIs like those in WinRT.

Anders Hejlsberg, by Gavin Clarke

Hejlsberg: "It is all about orchestrating execution"

In a nutshell, C# 4.0 will rewrite your code at compile-time to make it asynchronous. Developers can code almost as if it were synchronous, though they still need to pay attention to what is happening under the covers.

There are two new keywords: async and await. If you declare a function or method to be async, this tells the compiler to rewrite it for you. This does not automatically make it asynchronous, but only if you also use await in the body of the function.

The await keyword is used before a function call. The function then exits immediately, so the user can continue to interact with the user interface. If you wrote further code in that function, below the await statement, then this gets executed later, after the awaited function completes. C# preserves state such as the value of variables.

You can already get equivalent functionality in C# 4.0, using the ContinueWith method of a Task. The new approach is more natural though, especially as you can use multiple await statements in the same method. "It is all about orchestrating execution," said Hejlsberg.

By contrast, the compiler as a service project – codenamed Roslyn – is not just syntactic sugar. Microsoft is creating an API for the C# and VB compilers that will let you use them in your runtime code. In fact, it is building new compilers for C# and VB in managed code that both use and create the APIs. This will enable a number of new features, including evaluating C# expressions at runtime, more powerful refactoring and navigation tools, and a C# interactive prompt in Visual Studio.

Evaluating code at runtime was already possible, using a feature called Reflection, but Roslyn is both far more extensive and easier to use. Hejlsberg showed a ScriptEngine object that lets you use C# as a scripting language within your applications. You could use this to enable users of your application to run macros or extend it with their own user-defined functions.

"I'm not going to say when we ship this," said Hejlsberg, implying that it may not be part of Visual Studio 11, which will ship around the time of Windows 8. A Community Tech Preview (CTP) is promised for the middle of this month.

Developers may notice Roslyn more by what it enables, than by using the features directly. Tools in Visual Studio that generate or modify code will be more capable, because they can get a deeper understanding of what your code does by compiling it on the fly and inspecting the syntax tree returned by the compiler.

By way of example, Hejlsberg showed how a tool built with Roslyn can convert C# to VB and vice versa. It will be ideal for VB developers moving to C#, who can simply paste their old code; unlike those old Visual Basic 6 porting tools, this one will most likely work fine.

Maybe those skeptics who said that all .NET languages were really C# in disguise had a point. ®

Remote control for virtualized desktops

More from The Register

next story
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
You stupid BRICK! PCs running Avast AV can't handle Windows fixes
Fix issued, fingers pointed, forums in flames
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
First in line to order a Nexus 6? AT&T has a BRICK for you
Black Screen of Death plagues early Google-mobe batch
prev story


Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Go beyond APM with real-time IT operations analytics
How IT operations teams can harness the wealth of wire data already flowing through their environment for real-time operational intelligence.
The total economic impact of Druva inSync
Examining the ROI enterprises may realize by implementing inSync, as they look to improve backup and recovery of endpoint data in a cost-effective manner.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.