As developers, we prefer to automate wherever possible. Usually we automate computers, but it’s also possible to automate humans. Humans, after all, come with their own built-in automation system called “habit formation,” and we can cultivate helpful habits if we understand how habits form. Here’s an example from personal experience.
At Atomic Object, we’re very dedicated to test-driven development. The project I’m currently working on has 113 files of tests for a project with 154 files of logical code. Most code files are verified by a corresponding test file, so it’s important to update the appropriate tests before making changes to the code. Coming from a project that put more emphasis on full-stack integration tests rather than file-by-file unit tests, it was easy to forget to update the unit tests before diving into the code. Correcting this tendency required a bit of habit hacking.
Charles Duhigg’s excellent book The Power of Habit lays out a three-step framework for forming a habit. First, you need a trigger, something that cues you to carry out a routine. When you finish the routine, you need to receive a reward. Once you know the trigger, the routine, and the reward, the habit will start to form.
When working with the project’s code, I already had the trigger. Any time I opened a code file to make changes, I needed to open the unit tests as well. In fact, opening the unit tests was the necessary routine. Only the reward was missing. In place of a reward, I had a sigh, a tiny moment of dread. Sighs discourage habit formation — they’re the anti-reward — so first I had to figure out what I dreaded. A little introspection suggested that the chore of finding the right test file among 113 files sparked a flicker of dread. It was a simple task, but magnified into a sigh by my unfamiliarity with the codebase.
To undermine the sigh, I threw together a script to find the right test file and open it. The script took about six seconds to run — a delay that would spark more sighs — so I rewrote it to be faster. In the end, the script found the right test files in less than a tenth of a second. I was quite proud of the script’s speed once I finished. In fact, I was so proud that I inadvertantly discovered the reward to make my habit program complete. Every time I hit my keyboard shortcut to open the right test file, I beamed a little at how fast and how well my script worked — a tiny reward, but enough to make me look forward to updating the unit tests when I opened a code file. Looking forward to updating the tests kept me from forgetting that single most important step of TDD. Habit formed. Human programmed.
Habit formation is a powerful way to automate human behavior, and building habits is available to anyone. I wrote a script to automate away an annoyance, and the reward offered by running the script trained me to carry out an important routine. You too have tools available that you can use to build new, helpful habits, and if you have any stories about building habits, I invite you to share.