October 2008 - Posts
In part 1 we looked at CLR side-by-side support for multiple versions, at interoperability-related features and at DLR-related changes in the CLR.
There have been various complaints about performance aspects of the CLR that are sometimes neglected - the installation experience, the startup experience and the GC latency experience for high-performance applications. This feedback will be addressed in CLR 4.0:
- The .NET installer can be branded and customized, and begins with a 200K bootstrapper. Downloading, installing and NGEN-ing the framework all occur in parallel, enabling a faster setup experience with less clicks to install.
- Startup improvements (around cold and warm startup) might benefit client applications.
- A new client background-GC mode will allow garbage collections in the lower generations to occur in parallel with a concurrent GC of generation 2 that has already started. In other words, if a concurrent gen2 GC is running and your application triggers a low-generation GC, it will run concurrently with the gen2 and not wait for it to complete synchronously. (This is the client-side story; the server-side story is all about GC notifications, which are part of .NET 3.5SP1.)
From the debugging perspective, the big news is that 64-bit mixed-mode applications can (FINALLY!) be debugged with Visual Studio and that managed crash dumps (including mini-dumps) can now be opened in Visual Studio! With the addition of lock inspection debugger APIs, this doesn't mean that the WinDbg+SOS tandem can retire to greener pastures - but it does put Visual Studio hardcore debugging in a whole new perspective.
For greater reliability, the upcoming release will incorporate an opt-out feature that disallows catching state-corrupting exceptions such as access violations, and a code contract (design by contract) specification mechanism for static analysis tools to detect problems at the compilation phase.
This is all very exciting news, and rest assured that the majority of these features will be covered in my future posts. With one more session to go until the conference adjourns, stay on your toes because I'm not so sure the technology announcements have been completely exhausted just yet.
Joshua Goodman's session on CLR futures was packed - the crowd of developers wanted to learn what's been cooking under the hood for the past couple of years. Without a major CLR upgrade since 2005 (CLR 2.0), we all had our appetites whetted.
So to begin with, Joshua announced that as of 4.0, multiple versions of the CLR can be hosted in the same process. For example, an application leveraging CLR 4.0 will run on top of CLR 4.0, but will be able to load and interact with a module that requires CLR 2.0 and will run on top of CLR 2.0. (IIRC, this was already baked into the Silverlight version of the CLR.)
Another announcement Joshua made is that the source for the TLBIMP utility (used for COM interoperability) is hosted on CodePlex, making it possible to augment and correct problems with the generated interop assemblies for each specific project. This relates very well to the No-PIA feature I covered in an earlier post.
Similarly, P/Invoke interoperability solutions will benefit from the P/Invoke "Wrapping Tool" - which I believe to be a slightly updated version of the P/Invoke Interop Assistant. It can take any C/C++ header file and generate equivalent (albeit not always correct) P/Invoke signatures for managed languages to consume.
As part of the support for dynamic languages (DLR), the BCL now includes BigInteger (revived from 2007!) and Tuple classes (C++0x variadic templates would really be helpful here!), and a slight bug with tail recursion was fixed in the 64-bit JIT.
We live in exciting times - and this is not all that was unveiled in the session. Stay tuned for part 2 to discover what's new around exception handling, dump debugging, GC latency and 64-bit code.
The first session I attended on the first day of PDC was Misha Shneerson's presentation on a feature affectionately called No-PIA, or formally enabled by type equivalence and type embedding.
The primary motivation for this feature is to simplify COM interoperability scenarios and improve their performance, but it is useful for managed-to-managed applications as well, particularly those with extensibility requirements.
What No-PIA means in brief is that instead of generating an interop assembly or using a primary interop assembly supplied by the COM component vendor, you can embed the required interop types into your own assembly. This is similar to what you could achieve by specifying the interop types by hand without using a PIA - but you no longer have to do that by hand!
If you opt-in to the No-PIA feature (by enabling a property in the Visual Studio references property grid, or using the new /link compiler switch), you don't need the interop assembly anymore - which means it is not loaded and does not have to be distributed with your application. (Note that this feature is not intended for referencing managed assemblies - the referenced assembly must have an assembly-level [Guid] and [ImportedFromTypeLib] attributes. But it's probably "work-aroundable" as I will explore in a future post.)
The feature is secure even though it doesn't sound like it, because a verification is made every time a method is invoked. But don't worry - the verification is cached so that it only happens once for each call site. Oh, and note that only the types and methods from the interop assembly that you actually use are embedded into your assembly - so this could be a huge space-saver if you're automating Word to show a document but loading the whole Office interop assembly to do that.
However, that's not all. Not only does the size of the interop assembly no longer have effect on your application's distribution, but you can actually bind your code to previous or future versions of the COM component you are working with. This is enabled by the second part of the feature, called type equivalence, which requires a change in the CLR.
Type equivalence means that two different types with identical signatures can be considered equivalent by the CLR for the purpose of method invocation and cast operations. So you can compile your code against the (locally embedded) interop types of Office 2007, but if you're not using any new Office 2007 features, your code will also bind to Office 2003.
This is actually useful for managed-to-managed scenarios as well - especially where extensibility is involved. If type A is decorated with a [Guid] attribute and another type B is decorated with the same [Guid] attribute and a [TypeIdentifier] attribute, then these types will be considered equivalent by the CLR, enabling casts and method invocations to succeed from one type to the other.
In turn, that implies that you can compile a plugin assembly against version 1 of the shared interface and execute it at runtime against version 2 of the shared interface without binding redirects or any other magic. In fact, if you also use No-PIA you don't have to think about the shared interface assembly ever again!
To summarize, this is a really exciting feature that will enable easier interoperability and less headaches when producing and consuming extensibility applications. After the PDC I will certainly dive deeper into these features and showcase some possible scenarios that go out of the box.
Even though there are 7 people from Sela at the PDC (impressive considering the Israeli delegation size of around 20 people), we all have very different interests when it comes to choosing a session to attend. However, we were decisively unanimous when it came to Anders Hejlsberg's session titled The Future of C#.
Anders Hejlsberg is just that - Anders Hejlsberg. In an amazing presentation he covered the future of C# - what's going to be in the upcoming C# 4.0 release and what the future blueprints for C# vNextNext are going to be.
I'm sure this is going to be covered in the blogosphere, and covered again in my own posts - but here's the summary of features in the next release of C# - with the general saying that C# 4.0 is an enabler of dynamic programming paradigms.
Dynamic programming is enabled first and foremost through a new language keyword - dynamic. A variable that is of type dynamic exhibits runtime binding of method calls and cast operations. The binding itself is performed using pre-built or custom binders that invoke the operation. For example, binders are available for scripting languages such as IronPython, IronRuby and JavaScript, for COM interoperability, for XML access and various other purposes.
The following piece of code demonstrates what is now possible:
dynamic d = GetSomethingFromSomewhereAtRuntime();
int i = d.Foo(15); //Implicit return value cast from type 'dynamic'
This code will work for a COM object that has a method called Foo which takes an integer and returns an integer, it will work for a simple type that has this method, it will work for an object obtained from a scripting language such as JavaScript, and anything else that can be bound to at runtime.
A dynamic invocation is not necessarily a performance hit - call site caching and JIT tricks can result in a slow first call, but once the binding has been made, it can be invoked repeatedly without additional binding hoops.
This has lots of exciting applications, including the ability to provide generic operations without constraints - if the resolution is bound to runtime, the compiler won't nag you about missing constraints (and remember that some things such as operators are not available without constraints).
Other features Anders talked about are slightly less exciting, but still interesting on their own. The first one was optional and named parameters finally being available in C# 4.0. It's amusing that it took the C# language architects several years to realize what Bjarne Stroustrup engineered into the very first versions of C++, but optional parameters will significantly simplify VB and COM interop and end the annoyance of having a primary method with a gazillion parameters and dozens of other methods that accept a subset of parameters and call the primary method. Named parameters will make method calls more readable (even without the Intellisense tooltip), which is always a welcome addition.
public static void LogOn(
string username = "",
string password = "",
string domain = "");
LogOn("Sasha");
LogOn(domain: "Sela");
LogOn(domain: "Sela", username: "Sasha");
LogOn("Sasha", "Password", "Sela");
The next thing Anders discussed was covariance and contravariance with generic types - which is something that Eric Lippert has mentioned in multiple posts in the past while architecting this language feature. Essentially, it means that generic interfaces can be decorated in such a way that will enable output parameters to be covariant and input parameters to be contravariant, so that it's OK to pass an IEnumerable<Zebra> to a method that accepts an IEnumerable<Animal> if the IEnumerable<T> interface was declared as covariant.
public class Zoo {
IEnumerable<Animal> GetAnimals() {
return new List<Zebra>(...);
}
}
Finally, Anders briefly mentioned NoPIA - type equivalence and type embedding - which are features I will discuss in a later post.
At the very end of the talk, Anders showed off a couple of features that are likely to make into the next version of C# (after C# 4.0). He mainly demonstrated the concept of "Compiler as a Service" - the ability to use compiler services in an intuitive manner and to gain access to the compiler's AST and its object model. He showed a simple read-eval-print loop that provides semantics similar to interactive shells like Python and PowerShell - but all in C#.
To summarize, there are lots of exciting changes to the language which will primarily make it multi-paradigm, enabling dynamic and static typing patterns to further evolve in C#.
Oh, and I forgot to mention - I just got my hands on "The Goods" - a WD 160GB Passport drive with over 50GB of VPC images, walkthroughs, SDKs and other goodies. I'll keep you posted as I explore the vast amount of material we are all going to deal with in the next few months.
Today I finally started the business-related (but still entertaining!) part of my trip - the PDC pre-conference day. I attended the track on concurrent and parallel programming, which was led by Stephen Toub, David Callahan and Joe Duffy.
All in all, there was nothing astonishingly new in the talk - they covered parallelism and concurrency in general (and established a common vocabulary), threads in Windows, in .NET in particular, discussed the Asynchronous Programming Model (APM - a.k.a. Delegate.BeginInvoke) and at the end of the talk there was some time to discuss the Parallel Extensions for .NET, which will be released as part of the .NET 4.0 and Visual Studio 2010 wave.
Because all of the above has been disclosed and discussed before, I feel happy enough to reference past posts covering some (if not most) of the material presented today as far as the future release of Parallel Extensions is concerned:
One new thing though - as part of the .NET release, the concurrency data structures, the parallelization technologies (including PLINQ and the Parallel class) and all the rest of the cake - will be included in mscorlib.dll, System.dll and System.Core.dll. This means Parallel Extensions are not really a set of external extensions - they will be an integral part of the .NET framework and of our general programming paradigm.
In the next few days there will be lots of exciting announcements at the PDC, so this is a good time to refresh your blog reader every couple of minutes!
I'm sorry again for not letting you know in advance - Dina (my significant other) and I went on a trip to the US last Wednesday. We arrived in New York last Wednesday and spent the last week wandering around Manhattan's museums, restaurants and other attractions.
I'm not going to tell you about the standard attractions in exasperating detail, but I figure that a recommendation for some inexpensive breakfasts and lunches won't do any harm. Basically, we built our dining itinerary around the Frommers' guide recommendations, with minor alterations here and there. Bear in mind that we stayed on East 80th Street (cross 3rd Avenue) so often enough we explored the Upper East Side more than other parts of the island. Here's what we had:
- Day 1 - Tal Bagels for breakfast (moderate), Celeste (Italian - good) for lunch, Haagen Dazs for dessert (amazing as always)
- Day 2 - Breakfast at Bubby's (eggs and pancakes - amazing), Grimaldi's (pizza - amazing) for lunch, Brooklyn Ice Cream Factory for dessert (Haagen Dazs is better)
- Day 3 - Breakfast at Le Pain Quotidien (tartines, sharing platters - very good), lunch at EJ's Luncheonette (disappointing!), evening drinks at Gael Pub (so-so)
- Day 4 - Breakfast at Le Pain Quotidien, a few chocolates at Godiva Chocolatier (very good), lunch in Chinatown - Joe's Shanghai (good, but compared to what we ate in China it wasn't amazing)
- Day 5 - Murray's Bagels for breakfast (awesome!), lunch at Blue Smoke (barbeques - amazing)
- Day 6 - Breakfast at Le Pain Quotidien (a clear winner), lunch at the Afghan Kebab House (there are several so don't get mixed up - this one is really good), yet another Haagen Dazs for dessert
- Day 7 - Breakfast at Bubby's (again), lunch at Beekman Pub (burgers and club sandwiches - very good)
Another small tip that I owe to Noam Sheffer: If you don't have a US mobile number, you should definitely consider buying an at&t SIM with the unlimited data plan for just another $20. It's more than worth it when you navigate your way around Manhattan's streets using Google Maps, simultaneously checking out dining recommendations, reading restaurant menus and reviews, and tracking your way across subway stops.
What's next? Well, I'm writing this from the plane that's taking us to Chicago, where we will stay for 5 more days. Finally, we will continue to San Francisco and spend most of the time in that area until the PDC starts on October 26 (if you're there, say hi!).
After the PDC you can expect me (and other bloggers, I'm sure) to tell you all about the new exciting Microsoft technology that I currently can't discuss publicly. Let's just say there's a lot of it for everybody - distributed systems architects, business application developers, C# language fans, native (C++) linguists, mobile applications developers and many others. Let's just say that Oslo, C# 4.0, C++0x, Visual Studio 10, .NET Framework 4.0, Windows 7, Windows Mobile 7 and lots of other stuff should provide enough blogging material for years to come... I should start allocating blocks in my schedule for the entire month of November just to try blogging a few lines about each new announcement and technology of the 160GB swag that will be given away at the PDC!