spout

October 7, 2004 spout writing

You Too Can Be A Technical Writer!

October 7, 2004 spout

Settings, Collections and VS05b1 (oh my)

I sat down to write a new Windows Forms application in .NET 1.1 the other day, but the Visual Studio 2005 beta 1 called to me with its menu strips” and its user settings” and most especially its generics,” and I just couldn’t resist.

To start with, it was such a pleasure to add a menu strip, add in the standard menu items (including graphics), then just strip it down to just the menu items I wanted. Then, as I added new menu items, the menu item object names were set for me based on the menu item text, e.g. startRetrievalToolStripMenuItem instead of menuItem1, which was fabulous. Not everything was wonderful, e.g. I couldn’t drag and drop menu items or use Alt+arrows to rearrange them , but overall the new menu control was a pleasant experience.

Even more pleasant was the app/user settings model. To add a setting to my application, all I had to do was bring up the properties of my project, add a named setting of whatever type I wanted (more on this later) and choose whether it should be an Application setting or a User setting. Both kinds of settings are loaded automatically when the app starts and all I had to do to save them was call Properties.Settings.Value.Save() when my main form shut down. Then, with the settings in place, e.g. MyUserSetting, I could get to it after the app started from anyone in my app with a type-safe access, e.g. Properties.Settings.Value.MyUserSetting.

And this didn’t just work for built-in simple strings and ints and such like. Oh, no. I was allowed to add custom and collection types like System.Collections.Generic.List<MyNamespace.MyType> as well. Plus, using generics, the underlying XML serialization mechanism worked great, because all of the types are known at compile-time (settings are stored in standard XML .config files @ c:\documents and settings\<user name>\Local Settings\Application Data\<company name>\<product name_hash>\<product version>\user.config). Being able to declaratively set app and user settings of any type and then just use them in a type-safe manner, saving them with one line of code, loading them with zero lines of code and not having to flatten my collections into comma-separated lists made things so pleasant until I hit the ugly realities of beta software, especially as new features interact with existing features and each other.

For example, because the default AssemblyVersion attribute is set to 1.0.*” in AssemblyInfo.cs (which has moved to below the Properties folder of your VS05 project), every time I compiled, all of my settings were lost. That seems very counterintuitive to me. Why should a user lose all of their settings with the new version of the application? To work around this, I changed my AssemblyVersion attribute to a hard-coded string that I now have to remember to change manually, blowing the benefit of having a version number that changes automatically with each build.

As another example, like C++ const” of old, generics infect your code; use them in one place and you find yourself using them all over. That was fine with me (the generic Predicate<T> for finding things in a List<T> was so handy!) except that as of b1, the Windows Forms Designer gets all unhappy when you use generics. I have every hope that this will be fixed by b2, but as of right now, if I wanted to use the Designer (and it’s so sweet, how could I not want to use it?!?), I had to strip out any methods or properties in my visual code that exposed generics (although method and property implementations with generics works just fine).

Stripping out List<T> brought me to the use of ArrayList instead. That worked just fine (System.Collections.ArrayList is even available via the Browse button when setting up app/user settings) until the XML serializer couldn’t serialize instances of the custom type that I was using to populate my ArrayList. The error looked like this:

Could not use Xml serialization for setting: SelectedExchanges. --->
System.InvalidOperationException: There was an error generating the XML document. --->
System.InvalidOperationException: The type MyNamespace.MyType was not expected.
Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

When I start up the debugger to see the line of code where the error is happening, I ended up in Main because the code is part of the Application start-up for which there is no source code, making this even more difficult to debug. The problem was that the underlying serialization engine didn’t know what to do with this custom type. The clue was the mention of the XmlInclude attribute, which you can use to tell the serializer what types may be in the ArrayList, but you have to have somewhere to hang the attributes. In this case, that lead to a custom ArrayList type for the express purpose of informing the serializer (making me really miss the use of generics, where all of the types were specified at compile-type for me automatically):

[System.Xml.Serialization.XmlInclude(typeof(MyNamespace.MyType))]
public class MyList : System.Collections.ArrayList {
  public override object Clone() {
    MyList newList = new MyList();
    newList.AddRange(this);
    return newList;
  }
}

Notice also the Clone method. I added this later because the base ArrayList Clone method creates an instance of ArrayList, not my custom MyList type. Of course, since this was all run-time type errors, I couldn’t let the compiler tell me about these problems; I had to run my app and find them. Very frustrating, especially when generics makes these problems all go away.

Still, I’m very much enjoying the new productivity features in VS05 and Windows Forms 2.0 and when they work better together, I’ll be even more happy.

October 7, 2004 spout

Every Story I’ve Ever Written

I was working with a potential author on an article he’d like to write covering some ground I left uncovered in my original No-Touch Deployment piece for MSDN Mag. Anyway, he sent me the list of topics and then said the following:

There is a fair amount of material here it might benefit from being broken into chunks. I think I will write about small chunks at a time and then we see how much belongs in one article. Rereading your original article it struck me that you had [a] story that held it together, I need to find one for me.”

I’ve heard this kind of thing before, i.e. people ask how I turn a seemingly random set of topics into a story.” I’m all for that, but it’s not really such a chore. In fact, here’s the essence of every technical piece I’ve ever written:

So, I want to build this thing that needs to do this, that and the other. I started with this, did it this way and it worked. Now I need to do that. Oops. That didn’t work the way I thought it should. Here’s what I need to do to work around the problem. OK, now I want to do the other… [repeat]”

The secret is really building up from what the reader already knows with some minimal new, interesting thing and keep on like that til you’ve covered the ground you want to cover, stringing things together with transitions that give the reader the impression of one contiguous story. If you really want to get fancy, put a personal anecdote at the front that you use as an analogy, bring it up a few times during the piece and then wrap up with something clever that ties the your anecdote together with the ground you’ve covered by extending the analogy in a humorous way (but that’s optional).

September 29, 2004 spout

BankOne: Special Victims Unit

I have a BankOne Visa card that I use for Sells Brothers, Inc. as a charge card for expenses like computer equipment, technical book purchases and strip clubs (you know -- business expenses : ). Apparently somebody got a hold of the number and started making charges with it today. A $19 charge was approved, but the $331 charge swung the BankOne AI software into action and the charge was declined. They called right away to confirm the activity and when I didn't recognize it, they credited me the $19, canceled the card, put a new one in the mail, sent all three major credit card agencies a notice so that my credit rating wouldn't be affected and put an affidavit in the mail so that I could swear that the $19 charge wasn't mine. All of this defense against identity theft cost me 5 minutes on the phone, a few days wait while I receive my new card, a signature and $0. Amazing.
September 6, 2004 spout

The Week Before Burning Man

September 6, 2004 spout

The Week Before Burning Man

I was just listing my activities for the week before Burning Man and amazed even myself:

  • Shopping for and celebrating my wife’s 36th birthday

  • Helping to prepare for and then watching Sells brother #1 test for his Jr. Brown belt in karate (he was amazing)

  • Hosting my aunt and grandmother on a very rare 4-day trip

  • A day-trip to the beach

  • Celebrating the birthday of Sells brother #2

  • Coordinating the update, from my house and at the last possible moment, of more than 100 pages on microsoft.com to reflect the recent announcement of WinFX being made available on down-level versions of Windows (this included 3 all-nighters)

  • Preparing for and running a 2-day garage sale of the stuff I pulled out of my house over the last 8 months in my own personal episode of Clean Sweep

  • Packing for 5 days in the desert (I worried about survival and my wife worried about having enough costumes…)

Of course, after that I spent a week at Burning Man, and today we’re cleaning the playa out of everything, preparing the boys for school, hanging out with the relatives for Labor Day and celebrating our 13th wedding anniversary. Starting tomorrow, I have to figure out what to do with the Longhorn Developer Center now that WinFX will be available on down-level windows, co-author two Avalon books and one Windows Forms book and run the Applied XML Developer’s Conference 5. Should be fun. : )

August 16, 2004 spout

Where Are You In The Software Practitioner Triad

In his piece Software Practitioner Triad (I know it’s old, but I just got pointed to it by Phil Weber), Alan Cooper points out three different folks needed to design and build software:

  • Architect: responsible for determining who the user is, what he or she is trying to accomplish, and what behavior the software must exhibit to satisfy these human goals.
  • Engineer: technical problem solving via experimentation, not fettered with the demands of producing release code.
  • Programmer: producing a shippable product, consisting mostly of protective code that rarely—if ever—executes, but is dedicated to supporting obscure edge cases, platform idiosyncrasies, and error conditions.

I’ve done all three, but am happiest with architect and engineer. Where are you in your current job? Where do you want to be?

August 5, 2004 spout

Mensa Has an Open Enrollment Day

Mensa Has an Open Enrollment Day

I refuse to join any club that would have me as a member.” –Groucho Marx

I must fit into some kind of quota (Windows programmers? Authors? Norwegians? Big, Dopey, White Guys?) for Mensa to let me in

And don’t forget to steal the new flair, Rory… : )