How to Stay Motivated When Learning to Code
The Struggle to Stay Motivated
Do you ever feel like you are just reading online tutorials but not actually getting closer to becoming a Software Engineer? You always tell yourself that this time, you are going to finish the online course you started. But when you actually sit down to learn coding, it just feels like any other boring task like washing dishes or doing laundry. And you find it impossible to make any progress.
So, the question is, “How do you stay motivated when learning to code?” And that’s where Atomic Habits by James Clear comes in. If you have not heard about this book, you are probably not into self-help books at all. This book answers questions like:
- What are habit loops?
- How to prime your environment to make progress on your goals?
- How to use Dopamine Spikes to stick to good habits?
By answering all these questions, this article will show how you can build the life-changing habit of learning programming.
The Power of Small, Consistent Changes
Imagine a plane taking off from Los Angeles for New York. Just before the takeoff, the pilot accidentally changes the flight path by 3.5 degrees, which is almost negligible. It’s such a small change that neither the cabin crew nor the passengers notice anything. When the plane lands, the passengers find themselves doing a sniff test because they are walking on the clean streets of Washington DC instead of New York.
The point is that very small changes can completely change the trajectory of our lives. And just like the cabin crew and the passengers, we do not see the immediate results of these changes. But in the long run, the effect of these tiny changes compound, and the final outcome can be very different.
As a new programmer, you would think that you need to build something revolutionary to make it into the tech industry. But in reality, all you need to do is take small steps towards your goal every day, and you will be there before you know it. Keep scrolling Instagram or watching YouTube, and you will be no better a programmer than today in one year. Build tiny atomic habits that help you learn programming every day, and you will be very close to landing that Software Engineer job in one year.
Overcoming the Valley of Disappointment
Building habits is fine, but sticking to them is where the real challenge lies. That’s because you might not feel that your programming skills are improving from day to day. When you start learning programming, you expect to see a linear improvement. But here is what actually happens.
In the beginning, you will not see any results. James Clear calls this part of the graph “The valley of disappointment.” This is where most people lose motivation, give up, and go back to their old habits. But in reality, the returns for your effort are actually delayed. Once you go past this initial phase, you will start feeling like a superhuman. Learning a new language, building projects, and getting a job you want will suddenly start coming naturally to you. And when you look back at that first piece of code you wrote, you will definitely laugh at yourself. A common experience is looking back at an early portfolio website and chuckling at the design choices, like a rotating cube where each side of the cube had the name of one of a tech skill.
In the rest of this article, we will not just learn how to build these atomic habits but also how to stick to them.
Understanding the Habit Loop
Let’s start with how to build the habit of learning programming. Before we can answer that, we first need to understand how we build any new habit. And that’s where the “Habit Loop” comes in: Cue, Craving, Response, Reward. That’s the loop that builds any good or bad habit that we repeat over and over again.
Let’s understand the habit loop with the help of a bad habit that we all suffer from. The phone vibrates—that’s your Cue. You crave to see who the notification is from. Response: you pick up the phone. And the Reward: 30 minutes of Dopamine release scrolling Instagram.
Another example: - Cue: feeling bored with the tutorial. - Craving: want to see something entertaining. - Response: pick up the phone. - Reward: watched entertaining videos for another hour.
Soon, your mind starts making associations between watching YouTube when you're getting bored with the tutorial, and you end up building the bad habit of wasting your time during your programming session.
But can you use the same habit loop to build good habits? Let’s start with the Cue. When you want to learn programming, what is that one thing that you need with you without which you cannot even start your lesson? No, I am not talking about a cup of coffee here. I am talking about your laptop. Can you use your laptop as your cue and guilt you into learning programming? The answer is Yes, and that’s exactly what James Clear recommends in Atomic Habits. He suggests you should make your cue unmissable by placing it in the middle of your room—in full view.
Prime Your Environment for Success
Even better if you can place it where you waste the most amount of your time. If you play a lot of video games, place it near your gaming chair so it’s visible when you start a new game. A cue alone would not be sufficient; you also need to use implementation intentions to your advantage.
Studies have shown that often why people don’t stick to good habits is not because of a lack of motivation, but because they don’t have clarity of what they want to achieve. When you say, “Tomorrow, I will learn programming,” it’s just an intention that has no clarity. So, instead of saying that, you should attach an implementation plan to your intention. So, instead of just learning programming, you should say something like, “Every time the alarm goes off in the morning, I will get up and do a programming lesson for 2 hours on my desk.” By making this small change, you will provide your mind clarity on what to do right after you wake up.
Another way to do the same thing is by stacking habits. Stacking habits simply means attaching the new habit you want to build with a current habit. So, instead of doing a programming lesson when the alarm goes off, you would say something like, “Right after I brush my teeth (which I hope is a habit you have already built), I will do a programming lesson for 2 hours on my desk.” If you stack habits like this, you are more likely to stick to them if you practice them long enough. And don’t forget to place your laptop in the middle of the room for this to work.
Harnessing Dopamine to Build Good Habits
Cue along with implementation intention will give you the motivation you need to start learning programming. But, this motivation by itself is not enough to keep you going. That's because we humans don’t do things for which we get nothing in return. To understand why that is, we need to first learn about the motivation hormone, Dopamine.
In 1954, neuroscientists did a study where they blocked the release of Dopamine in lab rats with the help of electrodes. And what they found was astonishing. Without Dopamine, these rats lost their will to eat, drink, or reproduce. And as a result, all of them died. This sad experiment tells us how important Dopamine is for motivation, and here is how it affects us humans. Dopamine is released every time you swipe up on an Instagram reel. And the same Dopamine is also released when people do drugs. In both cases, Dopamine is responsible for creating the cravings that make us perform these bad actions again and again to a point where these actions become our habits. But can we trick ourselves into using the same Dopamine to build good habits?
An engineering student from Ireland named Ronan managed to use Dopamine to his advantage. Ronan wanted to become fit by exercising more but he could not find the motivation to work out. Instead, he would spend hours watching Netflix. So, what did he do to exercise more? He combined the two. He connected his bike to the laptop and wrote a program that would let him watch Netflix only if he was cycling above a certain speed. This is called Temptation Bundling. You take something that you already enjoy doing and use it as a reward for the habit that you want to build.
Here’s how you can use temptation bundling to help you progress in your programming lessons. You can write a program that tracks the amount of time you spend in your code editor. This program can then use this time to control the amount of time you get to spend on your phone. By doing this, you can directly tie learning programming to a habit that you already enjoy doing.
Make It Easy: The 2-Minute Rule
Another thing that can help you build the habit of programming is “The 2-minute rule.” When you set unrealistic goals for yourself, it becomes very difficult to stay motivated to work on them. James Clear recommends making habit building easy by taking small steps every day. He recommends starting with only 2 minutes a day. For example, if you want to build the habit of reading more, you can start by reading just 2 minutes a day. And if the book is interesting, you will be reading much more than that in no time.
For programming in Java, that would mean writing this function:
public static void main(String[] args)
And that would do us no good. So, here is a better approach: commit to doing “2 exercises a day.” If you stick to it for 30 days, it's highly likely that you will be doing much more than just two exercises a day by the end of that period.
Join the 10xdev Community
Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.