At Atomic, many people have read and enjoyed Cal Newport’s book Deep Work. This book is all about the importance and the art of achieving great things by eliminating distractions and maximizing flow.
Flow is a familiar concept to seasoned developers–“a state of complete immersion in an activity.” It’s a mental state wherein you feel like your code is basically writing itself.
While all developers (hopefully) get to experience flow states at least occasionally, staying highly focused while programming is a skill that can be learned and practiced. Here are some strategies that I have used to stay ultra-focused while coding new features for an application.
Though tasks like debugging and estimating stories also benefit from focus, feature programming is particularly conducive to flow states. These strategies might not work for everyone, but I highly recommend trying them!
1. Start With a Plan
Having a roadmap will keep you from slowing down to decide what your next step should be. The roadmap does not have to be long or detailed, and it doesn’t need to cover any implementation details whatsoever. Instead, it should be a simple ordered list of application layers or components that you need to cover.
Taking a simple React + Rails tech stack as an example, I might plan to first create a new React component to display information, then work on the front end’s API layer, then the server’s routes and controller, then database migrations and models, and finally implemention of the service layer. That outline will at least give me a rough idea of how much progress I’ve made at any given time.
2. Use Test-Driven Development
TDD has all kinds of benefits, the most obvious one being great test coverage for your code. But another advantage is that it forces you to plan out the code’s architecture, function signatures, etc. before you finalize the implementation.
This helps you maintain flow because test cases will help you make high-level decisions about your code, even if the tests don’t pass. You’ll need to get some (if not most) to pass in order to continue your feature development, but if a few tests are being difficult, consider moving on to the next piece of code. Just make sure your test suite is green before making any pull requests!
3. Capture Notes and Questions as You Work
If something crosses your mind but doesn’t absolutely need to be resolved at the moment, you should immediately empty it out onto a note pad or your favorite note-taking app. This practice will help you avoid context switching, which I think is the biggest enemy of flow.
Just make sure that your notes have enough information to be useful later. I also try to sort my notes (as I write them, as opposed to after I’m done working) based on whether they’re important and whether they’re urgent.
4. Be Cognizant About What Distracts You
The key is knowing the most opportune time to sit down and hammer out some new code. There are many things, and many combinations of things, that can affect your ability to focus throughout the day. These include the time of day, what and when you’ve eaten, your caffeine levels, background noise, music in your headphones, the weather outside, the temperature in your workspace, other responsibilities and stresses—the list goes on!
Whenever you feel particularly focused or distracted, take a minute to identify why. Over time, you’ll notice patterns in your energy and focus levels that will help you predict how you’ll feel later on. That way, you can plan the best (and worst) times to write lots of code. The goal is not to constantly stay in a state of flow, but to recognize when you can and cannot be in flow.
These four strategies have helped me stay much more focused while writing code. I hope you give them a try! If you have any other suggestions, I’d love to see them in the comments.