Microsoft's Roslyn invites VB to Windows 8 party

C# in disguise?

Boost IT visibility and business value

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. ®

Build a business case: developing custom apps

More from The Register

next story
KDE releases ice-cream coloured Plasma 5 just in time for summer
Melty but refreshing - popular rival to Mint's Cinnamon's still a work in progress
Leaked Windows Phone 8.1 Update specs tease details of Nokia's next mobes
New screen sizes, dual SIMs, voice over LTE, and more
Mozilla keeps its Beard, hopes anti-gay marriage troubles are now over
Plenty on new CEO's todo list – starting with Firefox's slipping grasp
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
PEAK LANDFILL: Why tablet gloom is good news for Windows users
Sinofsky's hybrid strategy looks dafter than ever
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
prev story


Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
The Essential Guide to IT Transformation
ServiceNow discusses three IT transformations that can help CIO's automate IT services to transform IT and the enterprise.
Maximize storage efficiency across the enterprise
The HP StoreOnce backup solution offers highly flexible, centrally managed, and highly efficient data protection for any enterprise.