Faster, Pussycat! Code! Code!
December 23, 2005
Roscoe, NY
It's hard to get good solid useful feedback on books that one's written. The publisher doesn't help, the books often aren't reviewed by magazines, and friends (obviously) can't really be totally objective and honest.
And so, the feedback-hungry author must resort to the unnerving task of reading amazon.com reviews, which are obviously a mixed bag.
The consensus about my first Windows Forms book seemed to be that it has too much graphics coverage and not enough real-life stuff (such as forms programming). I got the impression also that readers in general don't care for historical asides and extended discussions of typography.
But I don't think anybody has ever criticized one of my books for having too much code, and that leads me to my fourth rule for writing my Windows Presentation Foundation book:
Rule 4. It's all about the code.
I often read extended discussions of programming concepts, and the explanations usually make no sense at all, and then I see a few lines of code, and it all becomes crystal clear.
An example: The first time I saw the syntax for using an attached property:
DockPanel.SetDock(menu, Dock.Top);
it seemed very odd, and explanations of attached properties didn't help. Why are you calling a static method of the DockPanel class to indicate where the menu object is to appear in a particular DockPanel instance? At least to me, this statement makes much more sense when you know that the DockPanel.SetDock method basically converts that statement into this:
menu.SetValue(DockPanel.DockProperty, Dock.Top);
where SetValue is a method that the Menu class inherits from DependencyObject, and DockPanel.DockProperty is a static readonly field of type DependencyProperty. Looking at the SetValue call you can at least imagine that DependencyObject uses a generic Dictionary (or something) to store these two items, so that when the DockPanel object is performing layout, it can call the DockPanel.GetDock static method on all its children to obtain the Dock value associated with each child, including the menu object:
Dock dock = DockPanel.GetDock(menu);
Of course, the static DockPanel.GetDock method is actually implemented with the GetValue method from DependencyObject so that call to GetDock is equivalent to the following code:
Dock dock = (Dock) menu.GetValue(DockPanel.DockProperty);
I'll have a fuller explanation in Chapter 8, of course.
To me, nothing beats a little code for cutting through the crap, and my book will have plenty of it. (Code, that is).