Feeds

Microsoft's Roslyn invites VB to Windows 8 party

C# in disguise?

Combat fraud and increase customer satisfaction

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

3 Big data security analytics techniques

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Batten down the hatches, Ubuntu 14.04 LTS due in TWO DAYS
Admins dab straining server brows in advance of Trusty Tahr's long-term support landing
Inside the Hekaton: SQL Server 2014's database engine deconstructed
Nadella's database sqares the circle of cheap memory vs speed
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Internet-of-stuff startup dumps NoSQL for ... SQL?
NoSQL taste great at first but lacks proper nutrients, says startup cloud whiz
Windows 8.1, which you probably haven't upgraded to yet, ALREADY OBSOLETE
Pre-Update versions of new Windows version will no longer support patches
IRS boss on XP migration: 'Classic fix the airplane while you're flying it attempt'
Plus: Condoleezza Rice at Dropbox 'maybe she can find ... weapons of mass destruction'
prev story

Whitepapers

Top three mobile application threats
Learn about three of the top mobile application security threats facing businesses today and recommendations on how to mitigate the risk.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Five 3D headsets to be won!
We were so impressed by the Durovis Dive headset we’ve asked the company to give some away to Reg readers.
SANS - Survey on application security programs
In this whitepaper learn about the state of application security programs and practices of 488 surveyed respondents, and discover how mature and effective these programs are.