Writing a gadget was an ....interesting experience for me. And though I have legions of people to thank for helping when I got stuck, I did indeed write it myself....

It all began months ago, in May, when I was alone in a stark and industrial room with two shady characters....I mean coworkers....and the blinds were drawn. Or else it was windowless. Same thing.

Ed Harris, dev lead, said: (in a kindly tone) You crazy pm, we don’t have developers available for doing gadgets right now, we have to ship our product!

 

Patrick, the QnA developer with the most Javascript experience said (in a jaded tone): A gadget? They tell you step by step how to do it. It should be trivial. It would take me 20 minutes and 15 seconds precisely.

 

...But I don’t have time. I have to code the entire front end of QnA. Gotta go. 

 

Ed turned to Betsy after Patrick leaves:  Why don’t you dev it yourself? (in his famous  “ double dog dare you” voice). It shouldn’t that hard.

 

Closeup on Betsy who has not touched Javascript since 1999 : Maybe I WILL!

-------------------------------------------------------------------

 

Segue to a white tile kitchen table. (Betsynote: I don't know what it is this time, I did all my VB newbie articles coding in bed, but gadget felt like kitchen work to me). 

 

Betsy (on IM): Why won't it recognize my gadget in IIS? I'm following the intructions!

Friend: Drag the gadget directory into inetpub, it has to see it there. Forget the fancypants permissions setting.

Betsy: Ok, it sees it now.

 

Betsy goes out and buys two books, one on AJAX where she hopes to find sample code, and a Javascript book by O'Reilly. She wastes 4 hours on wild goose changes trying to take a shortcut by using their examples. They don't fit what the gadget is supposed to do.

 

Segue again to kitchen table. Betsy IMing a friend whose been a dev for a long time:

 

AIIIIIIIIIIIIIIIIIIIIIIIIIEEEEEEEEEEEEEEEEEEEE.

It's still not working!

 

Then later:

Betsy: Hey, it's working! Loookee here!

 

Even later:

Betsy: I broke it! (Whams head on table)

 

Figure this went on from May through August. The gadget had a few lifecycle stages:

 

1. Research and development. This is where there was no gadget SDK out, and Betsy was researching how other people did AJAX projects. Also, I quizzed Tim Hoad on the Image Search team how he wrote his gadget and got a copy of the code. Because I was relearning JavaScript, it would take me months to realize his stuff was so fancy I only had to steal about 25  lines, not counting disposing items.

 

2. The gadget SDK comes out. There's an RSS example in the sample code. Betsy  immediately swoops on it because creating the network request object is the biggest pain in the butt with RSS and Javascript...now the task is to make the sample work with the search box idea and QnA itself.

 

3. Refining the RSS formatting/bullets and that it doesn't "stack" but wipes clean with every search. I discover the pain of memory leaks in IE.

 

Cut to kitchen table scene: BAM! BAM! BAM! (head thwacking)

 

4. Suddenly (cue dramatic music)  my gadget stops working when hosted remotely.  The RSS feed just don't get called. And as we know, the RSS SDK sample was supposed to get me around the Javascript problem.

 

Seek debug help from Tatham Oddie, half the planet away in Australia (he's done TechEd demo sessions on how to write gadgets). He convinces me I'm not a madwoman.We escalate issue to gadget team. They fix some accidental misconfiguration in the gadget framework. It works again. Whew!

 

As consolation prize (maybe because my head is flatter now) they allow one of their developers to code review my gadget who has the coolest name next to Tatham's - Javier Garcia Flynn.

 

He kindly says it's not that bad,  fixes the head-thwacking memory issue by moving functions outside the initialization section, shows me where I need to put functions to dispose, and notes something not in the SDK (you can see it commented in my gadget) about initializing base.

// The gadget framework now requires you to call

// your base method last. This is because this call may alert potential clients

// of this class to this instance's existance and call methods on its interface

// when it is not yet fully initialized.

Specs to help you write your gadget - with less pain - are on the QnA blog:

http://liveqna.spaces.live.com/blog/cns!2933A3E375F68349!390.entry

6. We kick it live. Where I hope to the divine powers someone who is actually a developer, looks at it, looks at the spec, and decides to do a QnA mashup because as you know, it only takes 20 minutes and 15 seconds. For other people. :)