Narrative of an application

Last week I spoke at the London JavaScript meetup about JavaScript and AIR, and used the little Black Box application I’ve already blogged about as an example of (both) a reasonably well-structured JavaScript application and to demonstrate how easy it was to move such an app to the desktop using AIR. Preparing the talk reminded me of one thing that had been bugging me about the application design, which I mentioned at the meetup. I’d more or less decided not to do anything about it and leave the application as it stood, but in the end my conscience got the better of me, so I dug in once again.

I’d had two prior attempts at a representation of the core game objects, but both had held the ports (from which rays are fired into the box) and the cells (in which atoms may or may not be hidden) in separate structures. This led to some trickiness - and ultimately ugliness - in working out which port became the destination of a ray. While finishing the previous version it struck me that things would be simpler if the ports and cells shared the same 2-dimensional array. After a couple of hours work it was clear that this was the case: also moving some responsibilities from the Port object to a new class representing a path (previously this was just an array of elements) led to some other tidyings, and it’s this version of the code that’s now live on this site and available for download.

The unit tests helped, of course - even though many of them had to be rewritten. Going through the tests function by function (initially commenting out the ones I knew were failing, reintroducing and fixing them up one by one) was a great way of replaying the progression of thought toward the original implementation. This was the second strongest reinforcement in the experience: the first was understanding again that producing and considering design alternatives is such an important (and such a rare) activity in development.

No Comments

Add your own comment...