Jeffrey Richter combines a deep technical knowledge of .NET with a great sense of humour and honesty about where things went bad, to provide a useful overview of what's new in C# 2.0 and .NET 2.0. I find sessions like this useful in learning the story or intention behind features in the new technology, in a way that helps me understand them better.
The morning session covered an introduction to the new features in .NET 2.0 mostly around generics and anonymous methods. Seeing some demos on the new yield statement helped me understand more about how it works. He showed how you could use the yield statement to recursively walk all of the files and directories in the file system. The demo was simply writing out the paths to the console window and as it was running there were obvious pauses in its performance. Jeffrey said that these pauses were likely to be due to garbage collections, which highlighted that the ease of use of the yield statement came at the cost of performance (a class was created per directory/file which put a lot of pressure on the working set and garbage collection). Jeffrey mentioned the C# team have a solution which reduces the performance costs of iterators but it wont ship until after C# 2.0.
He mentioned that another approach to getting the flexibility provided by the yield statement without the poor performance, was to use generics and anonymous methods instead. For example, many of the generic collection types in .NET such as Array and List have useful generic delegate types, such as ForEach(Action<T>), FindAll(Predicate<T>) as Sort(Comparison<T>).
As an example, I can sort a list of string types and print them to the screen in just two lines of code using this techniques:
List<string> names = new List<string>(new String[]{ "Timothy", "Benjamin", "Samuel" });
names.Sort(String.Compare);
names.ForEach(Console.WriteLine);
Whilst I've enjoyed these methods before I did enjoy hearing Jeffrey's positioning of these techniques as a pattern to use instead of the yield statement. Jeffrey also mentioned that Microsoft had received many requests to add richer generic functionality to the generic collection classes. His company, Wintellect, have been engaged by Microsoft to write these collections and make them available for free download, and they are currently available as the PowerCollection library. Jeffrey believes that this functionality might eventually be made part of the Framework Class Library in future versions of .NET.
The great thing about Jeffrey's presentation is that draws on his experience as a consultant to the CLR team. For instance, he mentioned that having different security levels on properties, a 'new' feature for C# 2.0, was originally part of .NET 1.0 Beta 1 but that it was removed since the C# team viewed properties as just a special kind of field. From this perspective, having a different accessor made no sense. But as Jeffrey said, after a large amount of customer features, the C# team has put this feature back. it just took them five years.
Jeffrey is also not afraid to mention the things that the CLR team have done badly. He spoke about the justification for the static class feature of .NET 2.0. Apparently in .NET 1.0 the Environment class that only had static methods, but late in the beta cycle a developer added a HasShutDownStarted method but forgot to make it static. On top of this the Environment class had a private constructor so it was impossible for anyone to create a new instance of the Environment class and call this method. The worst part of this is that it showed that the developer had not written a single test to check the method that he added! If they had written a single test they would have seen that they could not have compiled the code that tried to write this method.
The session helped me see the benefits in understanding how a particular language feature works, particularly understanding whether it involves the language compiler or involves the CLR. This knowledge provides the background behind some of the constraints on the features (such as why you can have a catch block inside an iterator). The tension between the language compilers and the CLR was highlighted in the recent post-beta 2 changes to more fully support Nullable types in the CLR. Don Box's idea last year was that many of the changes going forward are going to be driven by 'syntactic sugar' using the language compilers, while Jeffrey was more upbeat that there's still innovation happening inside .NET and the CLR.
Jeffrey is razor-sharp technically and very funny. My favourite comments so was "Indigo loves using attributes. They use attributes so much that you no longer have to write code"
The afternoon session started with a coverage of partial types, before spending a long time on CLR hosting and how the SQL team helped ensure that the CLR could be hosted in a secure and reliable way. While Jeffrey is able to explain this stuff really well, it was a hard slog to keep up with the section on Constrained Execution Regions ... so I've nipped off to watch David Solomon and Mark Russinovich's Windows Internals section (or Sysinternals tools seminar as it seems to be).