Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Christopher Bennage

Our WPF book is now available!

February 2008 - Posts

  • Discovering Empty Try/Catch Blocks

    I've been burned by a few bugs recently due to swallowed exceptions.  In case you don't know, empty catch blocks will hurt you. Really, they will.

    I wanted a way to locate all of the empty blocks in our code base, I was playing around with NDepend and the amazing Code Query Language, but it's not able to do something like this yet.  (Patrick said that it will in the next version!)

    Then I realized that I was missing the simple solution. The Find and Replace dialog in Visual Studio.Ctrl+F and a regular expression!

    Here is the regex you'll need to find empty catch blocks in your solution:

    catch:Wh*\{:Wh*\}

    ":Wh" designates whitespace

    * means zero or more

    You have to escape the {} as they are special characters.

    Update: Note Dan's comments below. Here's an updated regex to cast a wider net:
    catch(\(.*Exception.*\))*:Wh*\{:Wh*\}
  • VS2008 Demo Challenge

    Last week or so, I stumbled on to the site for the Visual Studio 2008 Demo Challenge. The gist of the contest is to make a video explaining why VS 2008 is great, and then win stuff. Your video is played backed in a Silverlight app that your host at silverlight.live.com.

    So I make a video, and I think it's pretty funny.  I setup an app with Expression Encoder, and I'm feeling great.  I go to submit the video on the contest site and ... nothing. The site seems broken, which would explain the lack of videos in the gallery. (I had a bad feeling about the absence of competition.)

    I just don't have good luck with Microsoft contests. :-(

    Click here to watch the video. You'll need Silverlight 1.0 to view it.

    Update: I just heard that the contest died. Would someone still like to give me an Xbox for kicks? :-)

  • The Words We Use

    I just read this great post by Jimmy Bogard over at  Los Techies. He talks about user stories and the fact that what you call a user story is very important. (A rose by another other name would not smell as sweet. ) Words affect how we think about things; though we don't like to admit it.  I've definitely struggled with this myself.

    If you ever communicate with your clients, then I recommend checking out the post.  It's short too.

    I particularly like his comment that prioritizing a requirement is like putting lipstick on a pig.

  • XAML Only WPF Example (Font Viewer)

    The very first application I attempted to write in WPF was a utility to help me with choosing fonts. I'm a developer who has one foot in the designer world, and I am always looking for just the right font. I think that was about 2 years ago, and I was ecstatic that my prototype application took about 15 minutes to write and contained 3 or 4 lines of code (that's not counting the XAML markup.)

    When Rob and I began outlining our upcoming book on WPF, we decided to structure the it around four example applications.  The font viewer seemed like a natural choice for the first application because it's so simple to write., and easy to understand.  I showed the source to Rob, and in less than 10 minutes we had a 100% XAML version of the application. Yes, we removed those troublesome 3-4 lines of code.  :-)

    I decided to play around with it some more, and here is the result. It's a 24KB text file containing just XAML.  If you have .NET 3.5 installed, it should execute in your browser (both Firefox and Internet Explorer work).  It's a very simple application, but I think it's fun. I'm especially fond of the built-in tutorial (be sure to click the help icon).

    This version is a lot more complicated than the one we build in the book.  We don't introduce the concepts of styles, templates, animation, etc until after we're done with the font viewer. 

    In a nutshell, here is how it works. The list box is bound to the set of installed fonts on your system (System.Windows.Media.Fonts.SystemFontFamilies). There are series of four text blocks, whose font family is bound to the selected item on the list box.  Finally, the four text blocks get their content from the text box at the bottom. That's it.

    Please feel free to analyze, dissect, assimilate as you like.  You can get to the source using your browser's "view source" feature.

    Disclaimer: Only very recently did I bother to see if anyone else had done the same thing.  Yes, they had, and more.

    Bonus Question: How would you handle building an application like this with TDD\BDD? How does declarative programming collide with TDD\BDD?

More Posts

Red-Gate!