Coder's block is a period during which a developer struggles to write good code or any code at all. During a block, ideas don't materialize, and the overall goal of a project seems far and out of reach.
Writing code is a creative pursuit that requires using a combination of both the left and the right brain. All such activities sometimes run into a block that can be described as a lack of creative energy; this is a well-known issue with writing (it's called writer's block), but it affects coding just as much.
In my experience, coder's block is caused mainly by one of five root causes. I am going to examine each one of them, giving you strategies to recognize and overcome it.
Coding is a creative activity, but it must be focused toward the accomplishment of a goal or the resolution of a problem. When the target or the problem is not clear, it is difficult to get started.
To recognize if this is the problem you are experiencing, think about what you are trying to achieve. In particular, can you answer two fundamental questions?
- What goal are you trying to achieve?
- Why are you trying to achieve it?
Sometimes you might be tempted to answer "I am trying to get my project done" or "My goal is to keep my job," but that's not the type of goal I am referring to. Take yourself out of the picture. What you need to think about is the project itself. What is the purpose? Why is the project vital if you take yourself out of the equation?
If you can't answer the questions, try the following:
Do not even try to start writing code until you understand the goal that you are trying to achieve. Close your code editor and turn off your computer. It is a distraction, and it won't help. Instead, grab paper and pen and start thinking about the goal. Don't worry about how to achieve it, for now, just concentrate on what you are trying to do and why it needs to be done. Don't worry about the "how" yet.
Pen and paper give you a freeform way of thinking and taking notes; it releases you from the annoying constraints and limitations of software tools. Avoid staring at the white page; instead, write down everything you know about the problem. Describe the goal, and why you should try to achieve it.
Draw pictures if you want to, and take notes on anything that comes to mind. The act of jotting things down will get your creative juices flowing. Pen and paper stimulate both the left and the right brain, priming the creative process.
When you have done some thinking with pen and paper, get up and talk to somebody. Ideally, the person you speak to is someone familiar with the project, but it is not necessary. You could use a friend or a family member, explaining that you need to describe something you are trying to do and that you'd like to get their thoughts. The simple act of expressing something to someone is often enough to get your brain moving in the right direction.
If you don't have someone to talk to, explain the problem to your pet or a stuffed animal. It doesn't matter who you are talking to, or if they understand you. The important thing is that you describe your goal out-loud. Keep talking about it until it is more evident in your head.
Go back to pen and paper, and think about the goal some more. Review your notes, and see if you can answer the two fundamental questions mentioned above. If you can't, talk to someone again. Repeat the process until you feel that you can describe confidently what the goal is and why you need to achieve it.
The time invested in thinking about the goal might seem like a waste of time, and it won't feel like making progress toward a solution. However, let that thought go; it is a fallacy. You can't write code to implement "how" if the "what" and "why" is unclear.
If the "what" and "why" are clear, you might be stuck on the "how" because you keep on finding reasons why your solutions are not good enough; this is a common problem that I call "the self-doubt loop."
It occurs when you see issues with every solution that come to mind, and you can't settle for anything. As a result, you think in circles and make no progress.
It gets particularly bad when you start implementing a solution, and you find problems with it and change direction only to see more problems. You keep changing path until you get back to the first solution, and the cycle starts again. It feels like madness.
The best way to break that loop is to stop thinking about the problem for a little while. Get up, go for a walk, talk to someone, eat something, have a cup of coffee, do something else or sleep on it overnight. After a break, get back to the problem, list all the possible solutions that come to mind, list pros and cons for each and see if you can settle on one.
If you get stuck in the vicious loop again, go back to thinking about the purpose and make sure you understand it. Try to look at it from different angles. Try to re-define it and re-examine it. Ask yourself how you'd resolve the problem if you had to do it by hand and see if that helps. Think about it in practical terms, and with concrete examples to prevent over-abstraction or over-engineering.
It is entirely possible that a problem doesn't have a perfect solution. Choosing a path, even an imperfect one, is often matter of making a decision and sticking with it and dealing with problems as they surface.
Do not let "perfect" be the enemy of "good." Perfection does not exist, and most solutions are a compromise. That is normal and expected.
When you look at a project in its entirety, you might feel like the end is not in sight. Getting stuck on the enormity of the goal is a typical cause of coder's block.
Overcome this issue by putting the five fundamental problem-solving skills of software developers into action. Start by breaking down the overall goal into small sub-goals. Write them down in the order they come to mind. Once you have a list, make sure that they are well defined.
When you have a list, sort the sub-goals in the order you think you need to accomplish them. If any of them is too large, split it into smaller ones.
Once your problem is split into multiple smaller parts, tackle the first one and finish it. Focus on it entirely, without getting distracted by the overall goal.
Concentrating on one sub-goal at the time will get the coding process moving, and you won't feel so overwhelmed. Use the time spent achieving the first sub-goal as a measuring stick to calibrate how large the other sub-goals are.
Each sub-goals should be no more than one week worth of work; if any of them takes longer, you might want to split them into smaller ones. Avoid large sub-goals as they tend to cause coder's block for the same reasons that large goals do.
We discussed how knowing what you need to implement and why you are doing it is essential to make progress. However, even if you have the answers to those questions, you might not be convinced that the project is worth your time. That could be due to tedious work, or because the goal is to solve a problem that you don't find attractive or essential. Lack of excitement for a project is one of the most common causes of coder's block.
What can you do about it?
Maybe the project is not fun or exciting, but perhaps there are ways to transform it into a learning opportunity. For example, you could choose to use some new library or framework that you haven't used before. Or you could try to apply techniques or design patterns that you want to learn. There are countless ways to build the same piece of software, and learn something new can make even a dull project exciting.
Sometimes better understanding the needs of the customer can make a dull project more interesting. Take an opportunity to talk to some of the customers that are interested in the work you are doing, and find why it is important to them. If you don't have an opportunity to talk to customers, talk to customer-facing people in your organization, and find out why your work is essential.
Are there ways to tackle some of the technical debt as part of the work to get the project done? If the job you need to do requires integration with an existing system, perhaps you can use it as an opportunity to fix some old issue that has been looming for a long time. Find ways to inject some work you want to do in the mix of work you have to do.
Cause #5: Something in your life or the work environment is bothering you, and you can't concentrate on your work
Creative work requires focus; distracting thoughts could be the cause of your coder's block. Is something bothering you? Do you have personal problems that are interfering with your concentration? Or perhaps the work environment is creating unhealthy stress levels that are getting in your way?
There are several things you can do to overcome this kind of coder's block:
Sometimes you can't focus because you are concerned that you'll forget about something important you need to do. Make a list of whatever is on your mind, with the intent of getting back to it at a better time. The act of writing down your distractors is sometimes enough to get you out of a coder's block situation.
In some cases, you might need to take a break and prioritize fixing the issues that are bothering you. If the problems are personal, take a few days off to deal with it. Resolving something that is weighing on you, if possible, might be the best solution for your coder's block.
If the issues are work-related, take some time to deal with them. Talk to your boss, your coworkers, Human Resources, or whoever might be able to help you. Letting problems linger makes it difficult to break a coder's block.
If you cannot resolve quickly the issues that are bothering you, seek help. Letting worries or anxiety linger is exhausting and terrible for your productivity and health. It is best not to let it go for too long. There is nothing wrong with seeking professional help or help from friends and family.
Coder's block is a nuisance that you can overcome. It is similar to being stuck in the mud with your car. The natural instinct of stepping on the accelerator is going to make it worse. You need to be smarter than that.
The first step is to realize that you are experiencing coder's block. The second is to try to understand the cause. The third is to choose the best strategy to overcome it.
(open source and trusted by devs everywhere ❤️)