Paul Kimmel interviews "More Effective C#" author Bill Wagner on changes in C#, why LINQ is cool, and why he writes books.



In 1992, I read an excellent book entitled Effective C++: 50 Specific Ways to Improve Your Programs and Design. I still have the book. It sits on the shelf right in front of my desk. Effective C++ was written by Scott Meyers and edited by Brian Kernighan (of C programming language fame, a professor at Princeton).

Bill Wagner is continuing the series for the C# language, and Scott Meyers is his editor. Bill wrote Effective C#: 50 Specific Ways to Improve Your C# and is presently working on the follow-up book, More Effective C#: 50 Specific Ways to Improve Your C#. I talked with Bill about his experiences with .NET 3.5, LINQ, and his experiences writing books.

Interview

Paul Kimmel: Folks in the Midwest see you at user group meetings and code camps all the time. For people who have read your first Effective book, tell us about your day job.

Bill Wagner: I started messing around with software in the early 1980s and have been developing software professionally since 1986. In 2000, Dianne Marsh and I founded SRT Solutions, a small consulting company in Ann Arbor, Michigan.

Paul: You're also a board member of the Ann Arbor Computing Society and active with many other user groups. Your many contributions to the technical community led you to a regional director designation at Microsoft. What is a regional director?

Bill: I'm the [Microsoft] regional director for Michigan. In some ways, a regional director is similar to a Microsoft Most Valuable Professional (MVP). The difference is that a regional director encompasses a broad range of products, in contrast to an MVP, who is more focused on one single product.

Paul: Like the MVP designation, this is an unpaid position, but is recognition for your levels of contributions and feedback to Microsoft. What do you do as a regional director?

Bill: Regional directors provide feedback to product teams on designs and early builds, hopefully to improve these products. Toward the community, we provide information about new and upcoming initiatives that are being developed at Microsoft.

Paul: At user groups and conferences, that is, like the Professional Developers Conference (PDC). Are you going to the PDC in October in Los Angeles, and will you be presenting?

Bill: I am going as an attendee. I may be involved in some of the Open Space discussions, but I'm not presenting anything. I like the Open Space discussions because they're more conversational, and you get much more information on what challenges developers are facing in the real world. In most cases, I'm much more engaged when I'm involved and discussing, rather than just sitting back and listening to an eyes-front talk.

Paul: That's the same way I got through seventh-grade biology. Maybe an Open Space forum would be a great idea for user group meetings, too. Other ways you contribute clearly include your books. What was your first book?

Bill: I wrote the C# Core Language Little Black Book in 2001.

Paul: Your book More Effective C#: 50 Specific Ways to Improve Your C# (available October 2008) is like a sequel to your book Effective C#: 50 Specific Ways to Improve Your C#.

Bill: The C# language has undergone some remarkable changes since 2005, when Effective C# came out. There were enough topics to create an entirely new manuscript. More Effective C# almost exclusively covers new additions to the language since C# 2.0. Generics get a lot of coverage, as do iterators, which are C# 2.0 features that enable LINQ and the supporting 3.0 features. I also wrote two entire chapters on LINQ and C# 3.0, as there are quite a few items to cover. The remainder of the book covers topics that weren't covered in Effective C#—topics like multithreading and some advanced resource management. More Effective C# adds to the recommendations in Effective C#; it doesn't invalidate those recommendations.

Paul: What made you want to write a book in the first place?

Bill: I think it was insanity. But, truthfully, it's a great exercise to understand a topic fully. You must have a deep and clear understanding of a topic in order to explain it to a roomful of people. I'm sure you have the same experience when you're speaking or writing your own books. If there are topics that continue to excite me, then I'll write another book.

Paul: What made you decide to write these two books, specifically?

Bill: I spent a good part of my career developing in C++, before C# came around. Scott Meyers' Effective books were constant resources I used in those days. The format is very useful. If you can just keep your mind on the table of contents, you'll manage to write great software. It was also a more natural format for me to write. It's a series of essays, each of which describes one technique or one practice you should follow. I can continue to grow notes and create topics based on the questions I get from customers and the practices we develop [at SRT Solutions] to create high-quality software.

Paul: How much feedback did Scott Meyers have on your first Effective C# book and the upcoming More Effective C# book?

Bill: Scott is a very hands-on series editor. He provides quite a bit of feedback on the structure, the content, and the way it's presented. Scott doesn't provide a lot of technical review on the C# books, as he's much more involved in the C++ language. However, he's a brilliant guy, and he's able to improve my explanations on almost any topic.

Paul: What was the reaction to your first Effective C# book?

Bill: Quite a few people said that it helped them to understand a number of fundamental concepts in the C# language. Different developers told me that it helped them to understand why certain practices were accepted and certain practices are considered dangerous.

Paul: Since the books' messages are similar, although you have all new tips, how would you describe the audience for your Effective books?

Bill: One of the first bits of advice from Scott is that I should think of an Effective book as the second book a developer will read on a topic. Effective books are for professional developers who already have some knowledge of and exposure to the subject. In this case, More Effective C# is for professional C# developers who want to know more about using C# wisely, especially the newer language features.

Paul: How does More Effective C# compare to other books, such as O'Reilly's Cookbook series?

Bill: Most of the other C# books are comprehensive reference material. They cover the entire language syntax. Many even try to cover the bulk of the .NET Framework. Both of my Effective books assume that the reader already knows the syntax and some of the semantics of the language. My goal is to help them understand when to pick which language feature for what purpose.

Paul: Have you thought about how your book will help the reader? Can you elaborate?

Bill: C# developers have been given quite a few new features with which to work. The challenge is where and when to apply those new features. When should you use the query syntax? How should you apply extension methods to your applications? There are quite a few new tools and techniques to use. They all will help developers when applied correctly. However, like anything else, they can be misused. C# developers now have many new ways to write incomprehensible code—that's not going to help anyone. My goal is to show developers a roadmap of uses for these language features, making it easier for them to pull the right tool out of the language toolbox for the current problem.

Paul: There's a lot of buzz around Language Integrated Query (LINQ). You said there was a lot of coverage of LINQ in your book; what are your impressions of LINQ?

Bill: Personally, I'm very impressed with LINQ. It takes a while to get your head around the different syntax, and the new ways of expressing concepts. I like that now a developer can write middle-tier logic without concern for the storage for that data. The same query can be executed against databases, XML storage mediums, and objects in memory. Other people have created providers for Amazon, and other data sources. I really like the fact that algorithms now don't have to be rewritten for different storage mediums.

Paul: Do you have a favorite feature related to LINQ?

Bill: I like the deferred execution paradigm used by LINQ. It enables a lot of interesting uses. You can create algorithms that appear to operate on infinite sequences. Because the sequence gets generated as needed, you don't need to worry that the entire sequence space is way too large to work with effectively.

Paul: Does LINQ have "gotchas" that should worry your audience?

Bill: You can really get strange behavior if you mix deferred execution and eager execution. You end up getting different results if you modify variables after defining a query, but before executing it. It can lead to bizarre behavior and bugs that are hard to track. Both eager and deferred execution work, but mixing them can be very dangerous.

Paul: Where do you think LINQ will fit into the grand scheme of software development?

Bill: It's a huge shift for most developers. Very few developers know functional programming constructs. The overwhelming majority have spent their entire programming lives in either procedural or object-oriented languages. Functional languages traditionally have been reserved for academic use. The language features added in C# 3.0, while added to support LINQ, also support functional paradigms. So for the first time we have a language with both functional and object-oriented techniques as first-class language elements. It's getting a whole new set of developers interested in and exploring these concepts. I think it's going to be very significant and change software development. It's going to be a radical change for the C# community and for the software development community in general.

Paul: What are the benefits to the programmer using LINQ? What things can I do with LINQ that I can't do otherwise?

Bill: You can do anything without LINQ that you could do with LINQ. It's not like C# 2 or even C# 1 was crippled; there weren't whole classes of problems that you couldn't solve. However, LINQ enables new ways to approach many different types of problems. Because the syntax for Lambda expressions is much easier to create and read than the syntax for anonymous delegates, it's more likely that you'll write routines that expect Lambdas or delegates as parameters. The C# type inference capabilities are much better in C# 3.0 than in previous versions. It's much easier for developers to write generic methods and classes; developers using those methods and classes will be insulated from specifying the types as often as before.

Paul: Any advice for budding book authors?

Bill: Writing a book is similar to shipping software. It's an incredible amount of work, but it's extremely satisfying when you complete it. As an economic activity, it's not a great decision. You won't make the amount of money to justify the work. However, if you really want to dive deeply into a particular subject, it's very rewarding.

With that disclaimer, if you're still interested, the next step is to decide what you want to write. You must be deeply interested in a subject to write a book about it. Finally, look at your bookshelf. Pick a publisher whose books you read. Every publisher has its own style, and you'll be much happier trying to emulate a style you already read and find useful. As I said earlier, my copies of Scott's Effective C++ books are very well worn, so writing in that style was easier for me than molding my style to some other series.

Paul Kimmel is an architect for EDS and the cofounder of the Greater Lansing Area .NET Users Group (glugnet.org, Flint and East Lansing). Look for his new book, LINQ Unleashed: for C#. If you have a programming question, you can contact Paul at pkimmel@softconcepts.com.