Thursday, June 12, 2014

Inside out development

Building a new server component I realized I was going about it the wrong way.
Long ago I learned that only a small percentage of a program's code actually does work. The rest of it is configuration, validation, housekeeping, error recovery and the like.
And that's how I started developing my component: reading configuration files, setting up housekeeping. It was a long, discouraging slog because there always are bugs. Always are, and always will be.
Hours into the process I realized that I needed to start with the core: the small number of lines that actually do work.
The component's job is to return some data. I wrote a spec and a test for that code.
The spec is written in mocha. Here's the outline.

It uses a utility functionsetupServers to set up the server and messagePromise to send and test messages using Promises

  before ->  setupServers(<args>)
  it "provides the state of the networks and services", ->
    messagePromise
      send: type: <data>
      expect: type: <data>
Then I wrote the code to return some dummy data. It took a couple of lines. A few tweaks, it ran, and I checked it in.
router.on <message>, (message)=>
      router.sendInfo <response>, <data>
That's not the end of the story, though. Working on the test in a test file and the code in the server file is inefficient. We want to do it a different way.

No comments:

Post a Comment