How I design

time to read 3 min | 550 words

I was working all day of the initial design of a system, and I thought that I will speak about it a bit. Today was the very start, so I opened VS.Net and had no code to work with. I had some ideas that I thought I could try, but no real concrete ideas how to start. I had a test project ready, but I didn’t know what would be the first thing that I would write.

The problem here is that I had to deal with complex object graphs, and I knew in general what I needed to do, but the specifics needed to be coded, and I didn’t know how to write a test first to take a first bite of the problem. So I didn’t. Instead, I quickly proto-typed a test that showed a single high level feature of the system. In order for this to work, I would need to write quite a bit of code. In order to write this test, I had to name several key constructs of the system.

I then used the Class Designer (which is a really nice way to quickly design the layout of several classes, but I wouldn’t use it to write code after the first phase) to build interfaces to match those constructs, as well as skeleton of the operations that I thought I would need.

At this point, I’m still with bad (not compiling) test, and a whole bunch of code that doesn’t really make sense. I then dived into the code and tried to implement functionality. I got lost in the details several times, and the initial design was mostly wrong (a single interface remained unchanged from what I initially built, and that is because I didn’t touch this functionality yet).

What I did end up doing is having a goal in mind that drove my efforts; I needed to implement this feature, so I kept trying this and that. After several hours (and many changes to both code and tests) I finally had a test that compiled and run successfully. But it failed. I didn’t take into account un-rooted backward links in the graph, and I wasn’t certain how I should handle that.

I changed the implementation yet again, and this time I started to get the errors I like (expected “Foo Bar”, got “Foo “, etc). Those are errors I can deal with quickly, they require surgical fixes, not whole body transplants.

In no time at all, I had the test working. I got ton of code that I’m not testing, including a method that I wrote 30 minutes ago that I’m not sure that I understand.(CC of 12 and I can’t fit it all in one screen).

I don’t see this as a problem, I got something that I can work with, I now have an “integration test”, and I can safely touch the system (since everything in the system is directly related to this single test). The next steps are covering the code in more granular tests, and increasing my understanding of the design. The important thing, though, is that I now know what the application’s structure is going to look like. And that means that I no longer have to worry about the big stuff, I can deal with tiny increments as they pass through my mind.