On Petzold's Applications = Code + Markup

Tim Sneath walked into my office the other day and laid Charles Petzold's Applications = Code + Markup on my desk.  I'm only to Chapter 7 of 31 chapters and I am riveted.  I already have that feeling when reading a great novel when you don't want it to end.  It actually does read like a novel to me, with a narrative arch as it negotiates its methodical way through the WPF jungle of APIs. 

The book is pedagogically brilliant: not an easy feat with a platform as vast as WPF.  Like all great technology books, he starts with Hello World.  But where do you go next after Hello World when trying to tackle WPF?  This is where the book excels: Petzold slowly builds from Hello World in such a careful way, layering concepts that elucidate the underlying assumptions of the platform, yet at the same time never pandering to the user and always keeping it exciting.  By exciting, I mean that his samples and text show off WPF so that you aren't bored with pedantic samples that don't teach you something -- which, for example, I often find the SDK documentation to be guilty of, when it has a sample in the first place.  (Not to diss the SDK: those guys have a lot of APIs to document and they aren't finished yet.)

His samples are more than illustrative: they are downright clever.  In Chapter 4, he creates lightweight WordPad with open/save functionality in about 100 lines.  In Chapter 5, he creates a File Explorer using a WrapPanel, also in about 100 lines. His code is so tight and self-documenting that I find myself not even needing to run the sample itself to grok what he is trying to convey in the sample.

He never reveals more than he needs to, yet when he explains something, he gives you all the information you need.  It is like discovering WPF through his eyes as he unravels it himself.  Your guide through WPF is this erudite, scholarly computer programmer.  He is very careful with his language, making sure that the reader understand the subtle differences between the sometimes maddening WPF syntax, like the difference between ContentElement and ContentControl.  It is like being in the hands of a capable novelist with whom you know trust, like a Charles Dickens. 

Most exciting to me is how in the first few chapters he unpacks some of the core value within WPF around resolution independence and layout.  These features of WPF can get lost in the shuffle and often cause more confusion than clarity for people first coming to WPF, thus the common occurance of people resorting to use of the Canvas. He really hammers on how the layout system works, making the assertion at one point that you never need to set a width and height on an element.  I am looking forward to similar exegeses on other platform features like databinding and animation. To me, the book is an incredible validation of the platform by one of the most respected Windows programmers out there.

What really keeps this a page turner is the prose.  As professor once opined in a writing class years ago, if the voice is interesting, the reader will follow it anywhere.  Petzold's voice is indeed interesting.  Admist a discussion of the color system in WPF, he throws out, "The interior is filled with Alice Blue, the only color named after a daughter of Teddy Roosevelt."  Or, when introducing another very clever sample of the game Jeu de Tacquin (aka 15 puzzle), he provides some historical and cultural context around the the game, not only to computer science, but to the field of mathematics in general, which I knew nothing about.  Now I understand why Greg Schechter, WPF Architect, also implemented 15 Puzzle to demonstrate the platform features of WPF.

And then there are the unexpected, understated snarky comments that keep it fresh. For example, after limiting his samples to use no panels whatsoever for the first 4 chapters -- a feat unto itself -- he writes, "I'm sure there are many more marvelous and useful programs we could write with a window that hosts just a single object, but I can't think of any more.  And that is why we really need to figure out how to put multiple controls in a window."

Highly recommended both for learning WPF and for a downright good read.  I'd happily take this to the beach with me, a claim that I can't make for too many books about programming.