VS2010: What's new in languages

 By Tim Anderson

Visual Studio 2010 brings new versions of C# and Visual Basic to the .NET platform, together with a brand new language.

HardCopy Issue: 52 | Found In: Visual Studio 2010 | Published: 19/05/2011 | Last Revision: 19/05/2011

It was in 2000 that Microsoft announced its new .NET platform and with it a new language. Since then C# has succeeded beyond most expectations, and is now amongst the most sought-after skills in the industry, overtaking Visual Basic in the professional market and vying with Java in overall popularity. One reason for C#’s success is that Microsoft evolved it rapidly, responding to developer feedback and changing trends. New features in C# 2.0 included generics, nullable types, anonymous methods and partial classes; while C# 3.0 added implicit typing, extension methods, lambda expressions and query expressions. Many of these language changes go hand in hand with changes in the underlying Common Language Runtime (CLR). As a result, Visual Basic has been able to keep pace, and the CLR has been able to better deliver on its promise of supporting a variety of languages. In .NET Framework 4.0 and Visual Studio 2010, that capability is demonstrated by the provision of a new language, Visual F#, along with the Dynamic Language Runtime (DLR).

C# 4.0

The biggest advance in C# 4.0 is support for dynamic types. This is actually a new type, called dynamic, which is assumed to support any operation. If there are errors, such as calling a non-existent property or method, they are caught at runtime. The purpose of dynamic types in C# is more to do with interoperability with COM and with other dynamic languages than to make the language a rival to Python or Ruby. COM Interop is also improved by a new feature called Type Equivalence. This lets you embed type information for a COM library into your application. The first advantage is that your application can be deployed without the often large Primary Interop Assemblies for applications like Microsoft Office, especially since the embedded types only include the ones you actually use. Second, the types are loosely coupled, so they will work with any compatible version of Office, for example, instead of just the one for which they were compiled. The outcome is that COM Interop is easier, less verbose and more efficient than in previous versions. Another new feature, Covariance and Contravariance, allows the implicit conversion of variant interfaces that would previously have failed.

Visual Basic 2010

Changes to Visual Basic 2010 are aimed at ease of use as well as new capabilities. One that developers will welcome is implicit line continuation. Until now, VB developers have had to use the underscore character to split a statement over multiple lines, which is ugly and inconvenient. VB 2010 is smarter, and recognises circumstances where the next line continues a statement. One example is where the statement is within braces that have yet to be closed, such as: Dim result as Integer result = (1 + 2 + 3) Other examples include statements after assignment operators, or within embedded XML literals, after the dot in member qualifiers, and before and after query operators. The intent is that most of the time you can code naturally without needing the line continuation character, though there are circumstances when it is still needed. Another time-saving feature is auto-implemented properties. Instead of having to write Get and Set methods, Visual Basic will do this for you. If you type: Property MyProp As String = “My property” You can then reference not only MyProp but a hidden variable, _MyProp, which backs the property. In addition, VB 2010 has improved dynamic support, type equivalence and covariance similar to that in C# 4.0.

Visual F#

F# script screenshot
A DirectX visualisation created by an F# script.

F# is a new language which brings functional programming into the .NET mainstream. A functional programming language emphasises functions and expressions and aims to be safe, predictable and succinct. F# is based on the ML language, extended for object orientation as in Objective Caml, and comes out of Microsoft Research in Cambridge. It is a pragmatic rather than a pure implementation of functional programming, and has full access to the .NET Framework.



F# has several strong points. One is for mathematical expressions, and for code that makes heavy use of maths such as graphics manipulation. It is popular in the financial community because of its suitability for financial analysis. It is also ideal for concurrent programming, and has built-in support for asynchronous workflows. Parallel programming with F# is safer than with most programming languages. F# performs well, since it benefits from the high performance of the underlying CLR. Visual Studio 2010 comes with several F# project types including Library, Application, Silverlight Library and a tutorial. There is also an interactive F# console which you can open from the toolbar or with Ctrl-Alt-F, where you can try out F# expressions. For more information see http://fsharp.net.

Share and Bookmark  

Comments

Be the first to comment about this article...

Leave a comment

You must login to place comments.

Skin Border Image

Related Links

Skin Border Image