Please, keep it simple

Programming is difficult. Really difficult. There are many things to think about in different contexts. When a developer has an idea for a new feature, refactor or a new architectural change i have experienced that developers go into breadth of their idea before going into depth. Let me explain what i mean by breadth and depth in this context.

Lets say that you have an idea on how to refactor a module from the imperative style to an object oriented style. It includes adding some classes. Some of them define the interface etc. You get the picture. At some point you want to write some code to actual try your idea out. What i define as going into depth first in this context is if you define all interfaces and all abstract classes to support the actual functionality of the imperative module. And then you move on implementing these interfaces.

On the other hand we have going into depth first. When using that approach we want to write as little code as possible to showcase your idea. A class implementing a function might easily be enough. You can add an interface for understanding. You need to add just enough that it becomes easy to discuss when showing the code to a team member.

As you probably can guess from the title i tend to go with the depth first approach. One advantage is that you do not spend time on something that is not useful. Lets say you missed a key point and you would have to restart the design. If you have done the breadth first approach you need to throw away a lot of code. Which in my experience creates a biased towards that code – but that is for another post.

Another advantage is that their is less code your team members need to look at. This saves time and is easier to grasp. In the breadth first approach the actual idea might get lost in a lot of lines of code.

So lets not waste each others time when trying out ideas. Lets keep it simple and use the breadth first approach.

A good way to achieve this is by doing test driven development. Write a test that asserts on the result of your idea. When you get that test to pass you have a minimal depth first implementation of your idea.