Hammock-driven development

2019-03-30

Sometimes, the best thing you can do for your code is to stop thinking about it - at least consciously.

Programming, creativity and the hammock

In essence, programming is problem solving and problem solving requires creativity. This post presents some results from the research on creativity, specifically regarding the interaction between your conscious and subconscious mind, and applies them to programming and to problem solving in general. In doing this, we use some ideas from Rich Hickey’s talk Hammock Driven Development. Although Rich declared that his talk was based on experience rather than science, the advice he gives lines up well with what we learn from the actual research.

The conscious and subconscious mind

Research has shown that different parts of our brain work differently, are triggered at different times and and are good at different kinds of things. When solving a problem (which is what software development essentially boils down to), it can help to combine the efforts of different parts of your brain and let them help each other solve the problem at hand.

When consciously working on a problem, that work is being done in the left part of your brain. This part of your brain is very good at analysis and logic. If you solve a problem using a structured approach, the left part of your brain is doing the heavy lifting. However, the left side of your brain also has it limitations. While it is great at analyzing distinct things, it is not very good at seeing the bigger picture. Your conscious mind can help you overcome the obstacles on a given path, but it might fail to see an alternative path with far less obstacles on it.

The right side of your brain might not be as good at logic as the left side, but it is much better at looking at things from a distance, seeing the forest rather than individual trees, and making connections between things that may not seem related at first sight. If you’ve ever been hit by a sudden epiphany that solves a complex problem you had gotten stuck on before, that epiphany was produced by the right side of your brain. The solutions the right part of your brain comes up with typically seem to come out of nowhere, sometimes when you would least expect them. This is because the work done by the right side of your brain happens subconsciously, without you having any idea that your brain is still working on the problem. The right side of your brain only starts to work its magic when you stop consciously thinking about the problem at hand.

Feeding the subconscious mind

The subconscious mind can not start looking at the bigger picture and making connections if it has nothing to start from. You need fill your brain with information about the problem you are trying to solve in order to give your subconscious mind something to work on.

The way to feed your subconscious mind is to let your conscious mind do what it’s good at. Clearly state the problem, ideally in written form. Identify things you know, identify things you know you don’t know, identify constraints that limit your possibilities. Look for related problems and proven solutions that have been used to solve them. Analyze the benefits and drawbacks of those solutions. Try to find or come up with different potential approaches and compare them to each other, seeing where each approach shines and where it falls short. Identify gaps that you need to fill, mismatches, …

Ideally, write all of this down. Look at it regularly. Sit somewhere quiet, maybe even close your eyes, and just think about everything you found out about the problem. Make sure that your brain absorbs as much relevant information as possible.

After that, it’s time to let your subconscious mind play its part.

Triggering the subconscious mind

One important thing to remember about the subconscious mind is that it is subconscious. This means that you cannot consciously force it to think about a certain problem. However, there are some things you can do to increase the chances that the right side of your brain will start working on the problem.

Basically, all of this boils down to two things:

  • Make sure your subconscious knows that the problem is important
  • Stop consciously thinking about the problem

Hard work

If you just quickly glance at a problem and then go on to do something else, it is not very likely that your subconscious will continue processing the problem and potential solutions. You need to think hard enough, your really need to work on the problem, in order to get to the point where the problem seems important enough to your brain to keep on working on it in the background.

Frustration and relaxation

After all of this hard work, it is time to stop the left side of your brain from working on the problem so the right side of your brain can take over. You need to stop consciously thinking about the problem.

One way to achieve this is to work your conscious brain to the point of frustration, until it actually gives up on finding any solution at all. With your conscious brain out of the way, your subconscious is free the tackle the problem. When you get frustrated, the subconscious brain sometimes takes over very quickly, providing you with a great solution almost immediately after you’ve given up. Probably, this means the hard work you did and the frustration you felt put the problem at the top of your subconscious mind’s to-do list.

A more pleasant way to stop consciously thinking about a problem is to do something relaxing. You can go lie in a hammock. You can go for a walk or a bike ride. You can take a nice bath or shower. Ideally, try to do something that keeps your conscious mind occupied (preventing it from thinking about your problem) but doesn’t use up all of your brain’s resources. Research has shown that these kinds of undemanding tasks are very good at triggering your subconscious mind. Driving can help, especially if you know the way and there is not too much traffic. Even doing mundane stuff like folding laundry, going to the toilet or brushing your teeth can sometimes trigger an epiphany. And, finally, sleeping on it for one or more nights can also help.

Processing the results

So, you wake up in the morning with a solution to a problem you’ve been working on. What’s next?

First of all, capture the solution while it’s still fresh. Then, decide what else to do with it. You don’t necessarily have to start investigating it immediately. It is possible that the solution is not related to the problem you are currently working on but is actually related to another problem you worked on before. Or, maybe you woke up with a great solution to a problem you’re facing at work, but it’s currently Sunday morning.

When you do investigate the solution, it’s time for the left side of your brain to take over again. Analyze the solution, compare it to other solutions you saw, check if it violates some constraints you have, …

Sometimes, a solution that seemed great when you thought of it doesn’t seem so great anymore once you are fully awake and conscious. However, it often turns out that the solution is not that bad or at least gives you some new insights regarding the problem. And potentially, the solution may be so good and simple that you wonder why you didn’t think of it immediately.

Bonus: the power of interactions and the outsider effect

When you need to solve a complex problem, you don’t need to do it all by yourself. Other people can provide additional input, generate new ideas or offer a different point of view.

Those other people don’t even have to know that much about the problem you are dealing with. Sometimes, just talking to anyone (potentially a rubber duck instead of a person) can help you see the problem in a new light or expose flaws in your current approach. And sometimes, the best ideas for novel approaches come from people who don’t have that much relevant knowledge or experience. Exactly because they don’t know how this kind of problem is regularly solved, they tend to choose other approaches than the ones that have been tried so far by people who do have relevant knowledge and experience. Thinking outside the box is easy if you don’t even know what the box looks like. This is called the “outsider effect”.

If you find yourself stuck on a problem, any kind of interaction with others has a great potential for getting you unstuck. Use this to your advantage.

Resources