We all know that being stuck on a programming issue can be frustrating. As a developer, I asked myself how to overcome this feeling. In this post, I will share with you my top 5 tips to solve issues.
For the past few days, I've been thinking about: "What can I do if I get stuck on a programming problem". In the beginning, I did it for myself, but today, after spending my day stuck on several issues, I decided to share it. It could help a few people!
I created this list of tips based on my own experience as a programmer and teacher as a freelancer. I wanted to keep it short. Everyone can print it, put it on their desk, and read it every time they are facing this common issue.
90 percent of the time, when my students came to me with code errors these two questions solved their issue:
If an error is displayed in the terminal: "Did you try to search the error on Google?". Don't worry too much about finding the solution by yourself. If you have an issue, someone may have the same before!
"Did you take the time to print all the variables?". Code is about data, and most of the time, bugs appear when the wrong type of data is sent to a piece of code. My first recommendation will always be to take the time to display the content of all your variables.
As an example: if your issue is around line 50 in your code. Print everything before line 50 to have a global view of the problem.
It's always more practical to understand a bug when you have all the information in front of you.
Since I started to code, it happened a few times, and recently again. I'm stuck, and I'm sure to know the data-structure of my variable. In the end, when I printed the content, it was not exactly what I expected.
Most of the time, when we are stuck, we don't want to leave our computer. We think we didn't search enough. We want to start the same process again and again until finding a way to solve our issue.
"It's impossible, I should solve this issue. I've checked everything, how can it happen?"
If you recognise yourself in the quote above, you should take a break!
What I like to do when I'm stuck on a problem is take a coffee, then do something else. It can be, talk to my colleagues, read a blog post, or going for a walk.
I recommend you to find a relaxing activity—the one you can use anytime, and anywhere.
Once you are back to your code, you will feel more relaxed, and you will approach your issue in a better way.
Once you feel stuck on an issue, take the time to write it on the paper.
It's an excellent tool to summarise a problem and think about it.
Sometimes your computer screen can be disturbing. The reason is that you have many windows open with all your code stuff and it's hard to focus on the problem itself.
The goal of this step is to demystify the problem.
When you're programming on a project, you like to build beautiful code. Unfortunately, sometimes you have a solution to your problem, but it's not the best one, and you know it!
It's not a good move to stay on it for hours. If you want, you can set a timer to have extra time to think about it. But once it's ended, write your idea and leave a TODO's comment (
// TODO: Find a better way to do this.).
I like doing this when I know this is not the best way to do it. Most of the time, the next morning, you will open your computer, you will find a way to improve your code in only 10 minutes.
You can trust me because this is a developer fact! Most of my developer friends told me about this.
Don't be scared to ask other developers! If you think you've tried all the tips above, I would recommend following this shortlist to ask for help:
- Take a short break.
- Write your problem again on the paper. I recommend you to do it like if you're going to show this paper as an explanation of the issue. It's a kind of summary to explain your problem and organise your mind. Explain the problem to yourself another time. Are you ready to explain it to your colleague? At this step, do you feel more comfortable with the issue? Does this process give your other ideas to try? If yes, go back to your project and try them.
- Ask your colleague, and explain the problem in detail. If possible show examples or do a demonstration, it's better to understand the issue in depth.
We can classify this tip to the same category as the "take a break" one.
Sometimes you're tired of working on a specific part of your project, so switch to another task.
Don't take a long or difficult one; do something more simple than what you're doing actually. You will see how it's satisfying!
I want to share a recent example from my developer life.
In my company, I'm working on a new feature for more than three weeks. A few days ago, I was stuck in the implementation, and I started to become a bit upset. I wanted to finish, and I was frustrated.
I took a break from this task and moved on another small project which was more simple to develop. This project took me two days to do, and after I was super motivated and ready to go back to my previous main project.
If you want more content like this, you can follow me on Twitter, where I tweet about web development, self-improvement, and my journey as a fullstack developer!