FxCop-compliant Exceptions (Code Snippets vs. Item Templates)

Mr Haack posted recently about a topic near and dear to my heart: inheriting from Exception. To keep FxCop quiet, there is a surprising amount of code to write when creating your own exception types, as Phil notes: make it serializable, implement four constructors, etc. It can be tedious to do that every time you create your own exception. So, code generation is definitely the way to go, however, this is where I must respectfully part ways with Phil.

After playing with both code snippets and item templates, I find item templates to be a superior method for class-level code generation. Unfortunately, in all the betas of VS 2005 I’ve tried, there is no easy way to generate an item template easily (File -> Export Template never works, although I’ve not used any of the CTPs). I’ve outlined how to do it for beta 1 in a previous article. There are very few differences with Beta 2 and hopefully RTM (elements became attributes in the vstemplate file). Then creating a new FxCop-compliant Exception class is as easy as adding any class file to a project. On the other hand, a code snippet requires a file to already exist and if you’re abiding by the Microsoft’s guidelines of one public type per file (you are, right?), then you have to do all that work up front.

But the above advice is essentially useless for everyone: VS 2005 isn’t out yet (but it’s close)! Wouldn’t it be great to get this with Visual Studio 2003? Well, you can’t by default: that’s one of the reasons VS2005 is so compelling. However, there are third party tools to help you. Before it became not free, CodeSmith allowed you to generate code at the file level, so I whipped up this template file for all my Exception building needs. Just run it in CodeSmith (v2.x if you’re lucky (and cheap)). Of course, there is the way Phil does it as well. Your mileage may vary.

Download the CodeSmith FxCopException.cst template.

To be really nice to all 3 readers at jasonkemp.ca, I also whipped up an FxCopException item template for VS 2005. Aren’t I sweet? Just drop it in My Documents\Visual Studio 2005\Templates\ItemTemplates\

Download the FxCopException Item Template for VB
Download the FxCopException Item Template for C#

Drinking from a Firehose

It looks like another PDC is about to wind down. Just like last time, the amount of information is overwhelming. Nothing revolutionary this time, but some exciting stuff nevertheless.

By far the most exciting is LINQ (Language INtegrated Query): it’s got a catchy name and it’s got unbelievable power and potential. The coolest thing about LINQ for me is all the stuff that had to be done to enable it in the languages, especially C# 3.0: extension methods and lambda expressions being the coolest. This video will show you Anders explain it as only he can. From the demos he shows and his explanations, you get all kinds of features of a dynamically typed language with compile-time type checking: uber awesome. And they have a preview that works with Beta 2 of .NET 2.0.

Database stuff bores me to tears, so, like real database programmers, DLinq ain’t all that hot for me, for different reasons, though; but XLinq looks to be seriously sweet. When .NET first hit my school, the thing they touted most was XML: XML Web Services, XML comments in C#, XML Config files; “We make XML really easy!” But I was pretty disappointed with the verbosity and the amount of typing required to create a document or read a document. The new way, using XLinq to create XML documents right in the language, is just gorgeous. It makes creating documents intuitive and easy. Can’t wait for that.

The other things are worth noting, but nothing I’ll use daily, like the above. I’m curious to see the Office UI in action. It could definitely have a big impact on applications in the future. But making it a developer platform? Boring! Equally boring is WWF and WTF. Those definitely won’t get you laid:

Girl: What programming tools do you use?
Boy #1: Windows Workflow Foundation.
Girl(with disgusted look on her face.):   Later!
Boy #2: Python and Ruby on Rails.
Girl: Ooooh. Hello.

Computer Books Every .NET Programmer Should Own

Given my natural distaste for Computer Books, and my penchant for lists, here are my picks for Computer Books That Don’t Suck (.NET Version):

You may notice that almost all of these books are written by authors who blog. (Whether the blog or book came first is another, irrelevant discussion.)

The two books that get my absolute, trapped-on-a-desert-island recommendation are Joel On Software and Coder To Developer. I was unable to put down either of those books until they were finished. And then I wanted more of that. Interestingly, the last two books on the list are the least coupled with .NET.

This list will expand. Do you have any books you simply cannot do without?

Announcing Subtext

Phil Haack has decided to fork .Text, my blogging engine of choice, and I couldn’t be more excited. I batted around the idea of writing my own from scratch, or forking it myself, but I just didn’t have the balls. Fortunately, Phil does have the balls.

Since I’ve been using .Text for almost a year, I know what I just can’t stand about it, what I need to change. That’s why this has got me so excited. This is probably the only open source project I’ve seriously thought about contributing to. Looks I got something to look at this weekend. 🙂

Firefox Authenticates when launched in VS 2005

Firefox is my default browser. I imagine others have the same default browser. These bug reports in the Product Feedback Center will help you out: