Geeks With Blogs
Path Notes of a Kodefu Master blog

The next versions of C# and VB will have improved parity between them. From the consultant perspective, this is important because one can't always choose which language to use. Although a seasoned C# developer can program in VB as well, it seems that gotchas appear and you have to refer to the documentation to figure out how do something that you wouldn't even need to think about in your primary language.

The goal of the Visual Studio Managed Languages team is to maintain the character of each language while introducing the same new features to both. In keeping with this spirit, they've introduced features from one language to the other while maintaining the target language's style and feel.

New C# Parity with VB

Late Binding - Although the new dynamic type isn't the same as late binding in VB.NET, it is similar in many respects.

Named and Optional Parameters - No longer will you need to chain tons of overloads. VB developers have mocked us C# developers a while about this. It also cuts down on the number of parameters you have to pass to COM method calls.

New VB Parity with C#

Auto-implemented properties - These are idential to C#'s auto-implemented properties in that the compiler will create a backing private member for you. However, VB does not get read-only or write-only auto-implemented properties.

Collection Initiliazers - No more have to call List.Add(...) over and over.

Array Literals - The compiler will now figure out what kind of array it is based on the types used to initialize it. 

Multiline Lambdas - The compiler accomplishes this by figuring out the widest type returned from the multiline function.

Implicit Line Continuation - C# has implicit line continuation for everything, since line termination is denoted by a semicolon or the ending of a block of code (curly braces). VB, in contrast, implicitly terminates lines and oftentime requires a line continuation character (underscore). The line continuation character is now eliminated for scenarioes where it makes sense that the line should continue. The rules for this are as follows: after an attribute, after a comma, after a dot, after a binary operator, after a LINQ query clause, after a parenthesis, after a curly brace, and after a <%= or %>.

New features added to both

Generic Variance - Remember the question about assigning a list of strings to a list of objects? Well, you still can't do that due to type safety. However, sometimes the generic only goes out. Conversely, sometimes it only goes in. You will soon be able to declare your generics that way, and it will allow things like an IEnumerable<string> to be assigned to IEnumerable<object>.

Compiling without Interop Assemblies - It used to be that a primary interop assembly (PIA) had to be distributed as another artifact with your application. This is terrible when you're using a small subset of the functionality: it could dramatically increase the size of your distributable. Worse still, it is possible to run into a dll hell situation with different versions of the pia. In .NET 4.0, you can have it compile the piece of the primary interop assembly used by your application into the executable, greatly reducing distributable size and versioning issues.

 

Most of these features are demonstrable in the Visual Studio 2010 CTP; with the exception of in and out generics. These features appear to be very useful and stable. Although CTPs are subject to change, I suspect these features will make it to the final release.

Posted on Saturday, January 10, 2009 6:47 PM Kodefu | Back to top


Comments on this post: Parity Between Languages

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Chris Eargle | Powered by: GeeksWithBlogs.net