Here comes the source code for the .NET Framework

Scott Guthrie announced today that the source code for the .NET Framework will be released with Visual Studio 2008. That's just awesome. Check out the post for the debugging scenario here, it's beautiful to just step right into .NET code. Of course you could have fired up reflector in the past, but this is much more streamlined and bonafide.

This is pretty genuine transparency and will give customers lots to be happy about.

Roadmap for VSTS

Microsoft has just released (here) a moderately detailed description of where Team Systems is going over the next 12 months or so. The roadmap also includes the beginnings of the functionality that will be found in the next version of VSTS (code named Rosario). Nothing like a little transparency to get people salivating. :)

Follow up on LINQ and ADO.NET Entity Framework Talk

On Saturday on March 31, 2007 I did a couple of talks at the Toronto Code Camp. The first an overview on the LINQ Project and the ADO.NET Entity Framework.

The second talk was an impromptu talk to cover a time slot for a speaker who was unable to attend. I gave the audience some choices of topics and they chose Automated Unit Testing in VSTS. We also touched briefly on the bridge between TDD and QA, other types of tests, integration with source control, work items and builds. My hidden agenda was to convince folks that this is an essential evolution of our develop discipline and is no longer a fringe activity, nor associated to just one kind of development methodology (XP/Agile).

The talk was unscripted and as such no slides. Good thing because we went well into the lunch hour and I appreciate everybody's willingness to hang out and have a good discussion. Here are some links:

And lastly a couple of book recommendations:

Finally a big thanks to Chris Dufour for putting on an excellent glitch free code camp - this should be a model for similar events.

Update: Also check out this blog post for videos of the EDM designer that unfortunately isn't working in the March CTP.

Update 2: I should also include Shyam Pather's excellent Entity Framework screencast tutorial(s) in which he demos Entity Query Language and tells a great story of how to evolve ADO.NET 1.0/2.0 code to ADO.NET 3.0

Visual Studio Pro to get Unit Testing in Orcas

One of the biggest wrongs in VSTS 2005 was that the Team Architect edition didn't have unit testing. Not only has that been rectified for the Orcas time frame, but this feature has been moved down into the Visual Studio Professional SKU for the next release in Orcas. Fantastic! [via VSTS Quality Blog]

So long John

In case you haven't heard, John Lam is leaving ObjectSharp (and Toronto) for Microsoft (and Redmond) in January of next year. John will be taking his passion and expertise for Ruby and Dynamic Languages and helping out the CLR team buff up its support in that area as a Program Manager. As you may know, John has spent most of his time recently at ObjectSharp on the RubyCLR Open Source project. We'll be figuring out what to do with that over the next few months when John makes the transition to Microsoft. Check out John's blog if you're interested in stepping up to the plate to help out.

On a personal note, I'm sorry to see John leave, but you have to follow your heart and your passion so I wish him the best of luck in his new role. I'll be keeping very close eye on his kool-aid drinking, pill popping, MS assimilation process and can hardly wait to jab him as soon as he starts adding “super” in front his emotions :)

Good luck John.

Claudio Lassala @ Houston .NET UG on LInQ Mar 9, 2006

Fellow MVP Claudio Lassala will be speaking at the Houston .NET UG March 9th from 6:30-8:30pm, on one of my favorite topics: Language INtegrated Query (LINQ).

Class design considerations for extension methods and anonymous types

One of my readers was watching the DNRTV episode I did on LINQ recently and had this question: 

At some point, when you're explaining object initializers and anonymous types, you say something regarding extension methods, like how they could be used with the anonymous types. I'm not sure how that'd work: if the anonymous type gets named dynamically as something like "<Projection>F__4", and if the extension is declared during compile time as something like "method (this type)", how can we extend the dynamic class?

He is correct in pointing out the difficulty. These projection or anonymous types have dynamically declared names and when you declare an extension method, you must specify the type after "this" in the argument clause.

One thing that is not obvious is that the type specified after “this” in an extension method doesn't have to be the exact type, but can be an ancestor or interface implemented by the type you are ultimately wishing to extend.

public static float GetArea(this IPolygon shape){...}

As an example, the above extension method could be used as an extension method over anything that implements IPolygon.

The downside is that anonymous types (and linq projections) inherit directly from object and I don't expect that they will implement any special interfaces (the goal is too keep them simple for C# 3.0). What are you left to do? Create extension methods on "object". That is certainly a theoretical option I suppose, but that seems a little bit extreme.

To be honest though, try to think of real cases when you'd want to extend an anonymous type. If the type is truly anonymous, you know absolutely nothing about it, and what assumptions can you really make about it in an extension method? Truly, in some cases, you are going to choose to implement a named type instead of an anonymous type, and it appears that we'll see refactoring support in the tools to promote an anonymous type to a real type. This is a very likely scenario.

The reasonable cases that I can think of where anonymous types are the preference (i.e. I have no burning need to have a named type) but still need (and can) extend them, is when they are used in the context of a collection or another generic type.

For a good example of that, let's take a look at some of the extension methods provided by Linq itself.

  public static class Sequence {

    public static IEnumerable<T> Where<T>(

             this IEnumerable<T> source,

                  Func<T, bool> predicate) {

      foreach (T item in source)

        if (predicate(item))

          yield return item;

    }

  }

Consider that this is an Extension method for anything IEnumerable<T>. In this case, we're using this extension method against an IEnumerable collection of type <T> - a generic. That generic type could be an anonymous type. But the important information here is that we know something more about the anonymous type here and that is that it's used inside of an Enumerable collection, and hence we can provide the value of iterating through it in the foreach, evaluating some criteria, and yielding the items that pass the criteria into another collection.

How Do I Revert a Changest in Team Foundation Source Control?

This question came up in our VSTS for Developers Training Course in Toronto this week. One of my students wanted to know how to undo or rollback a checkin, something you could do in Visual Source Safe.

Unfortunately this feature was cut for V1 of Team Foundation Server. Buck Hodges and Brian Harry from Microsoft share how this was a painful cut to help get V1 out the door in this forum post. 

Update: James Manning (via the comments) points out that the Team Foundation PowerToy will do this for you. Great tool btw - check it out. Includes the following tools: Unshelve & Merge local changes, Rollback, Online (syncs offline changes to source control), Get Changset, and Undo Unchanged.

Vancouver Launch of Visual Studio and SQL Server 2005

I'm in British Columbia for a few days for the Vancouver stop of the Canadian Launch of Visual Studio and SQL Server 2005. They are expecting a great turnout - should be one of the largest MS events in town in recent memory. Last night we had a User Group reception and I got a chance to meet some of the local community leaders and technorati.

  • Rob Chartier is a smart guy who is going to be working at the Ask the Experts Cabana area as well. He is also working on a Code Camp out here in Vancouver on March 18th. Registration is now open.
  • Shaun Walker of DotNetNuke open source portal fame was also there. We had some interesting conversations around the challenges of managing an open source project. I was happy to hear how commercially successfully they were as well.
  • My friend Mike Flasko was also up from Redmond. He is now the Program Manager for the System.Net team and is doing well in his new role at Microsoft. They have some pretty exciting stuff in the works for Orcas and beyond. He also has an open call on his blog for feedback on what you want in Orcas for System.NET.
  • I also had a chance to meet Graham Jones who runs Vantug out here.

All in all in was a fun evening. Ilya Bukshteyn is up from Redmond to do the Keynote presentation which I'm looking forward too. John Bristowe and Ilya are sure to have some lively banter during the demos.

What Inferred Types in C# 3.0 are Not!

I had the opportunity earlier this week to listen on a MSDN chat covering the enhancements to C# that were unveiled at PDC. Listen being an imprecise term given that it was a chat, you understand.

I had two main takeaways from the chat. First, there was a ton of interest in LINQ and the various inner and outer workings of that. I’ll post some observations on that shortly. The second thing I learned was that there seemed to be a high level of confusion over exactly what inferred types are bringing to the table. I think that the real problem is that they don’t bring nearly as much as people expect/want/are afraid of. Please allow me to put the underlying thought into my own words.

In its simplest form, an inferred type looks like the following:

var a = 1;

The ‘var’ keyword is used in place of a data type. At compile time, it is inferred that a is intended to be an integer. From that point forward, the compile treats a as if it had been defined as:

int a = 1;

So much for the simplest case. And, in fact, using this as the example is a bit of a problem because no one should ever write code this way. In this simple a case, you should use the second code rather than the first. This makes it difficult to understand when inferred types are even useful. So let me pull the example that was used in the chat:

Dictionary>> peopleOrders = new Dictionary>>();

Now everyone who thinks this is easy to read hold up your hand. In this blog, where there is no syntax coloration, it’s hard to figure out what the name of the variable is, much less what the type is. When this code is read, the programmer will have to give it a second or third glance to get what is going on. And since variable declarations are not normally that important to the business logic of a method, all this syntax does is add friction to the process of understanding. So consider the inferred version:

var peopleOrders = new Dictionary>>();

Isn’t this much easier to digest?  I’m sure that even those people who put their hands up for that last question will agree. At that, ultimately, is the purpose for inferred types. To reduce the friction involved in reading code. Strong typing is still in place. Programs are still type-safe. Casting exceptions will still be thrown when appropriate. In other words, inferred types are just a way to pretty up the syntax of C#. And given some of the code that I’ve looked in the past, anything that helps keep modules cleaner is worth it.