Bill Wagner on Generics

To complete the user group trifecta for the week, tonight I attended the Dayton .NET Developers Group meeting where Bill Wagner spoke on generics.  Thankfully, he didn't spend any time talking about generic collections.  Instead, he focused on generic classes and using generic methods on non-generic classes.  A couple examples struck a chord with me.  The first was when he created a  generic Tuple class to be able to return two values from a method, because of his declared dislike of out parameters.   I'm not a fan of out parameters either, so this seemed like a good idea.

The next example I liked was to serialize and deserialize objects to and from XML.  I know I've written that code plenty of times without using generics.   He developed this example quite a bit, introducing compression to the XML storage, and refactoring the code to eliminate duplication through the use of anonymous delegates.   In the end, the code using the anonymous delegates was not a clear as the original code, even though he eliminated duplicate function.  This led to him writing the generic serialization using the lambda expressions available in C# 3.0, which greatly enhanced the readability of the code.  It does make me look forward to C# 3.0.

And just for good measure, at the end of the presentation, he threw in an example of using the new LINQ query syntax and talked about how it related to the generics and anonymous delegates/lambda expressions.

I enjoyed the presentation and would highly recommend Bill as a presenter.  I've already used generics beyond collections, but this presentation has inspired me to look for more ways to take advantage of generics.    Bill is also speaking tomorrow night (August 23) on C# 3.0 at the Central Ohio .NET Developers Group

0 comments: (+add yours?)