Bugs? What can you do when your code doesn't work?
On this page we've collected together some tips and suggestions for when you're having problems coding: when your code doesn't work or you don't know how to make the right thing happen.
No matter which coding language you decide to learn, you'll come across plenty of errors and times your code doesn't do what you expect.
Errors are a normal part of coding and everyone, including professional programmers, get them all the time. Here are some tips for getting to the bottom of them and finding ways to make your code work again:
Read the error message - Sounds obvious, right? If you get an error message when you run your code, read it and look for any clues, such as where in the code it is breaking or what kind of error the computer thinks it is. If you don't recognise/understand what it's saying, try searching online for that error message.
Know what it is supposed to do - Another obvious sounding one, but it can be very useful to define exactly what it is meant to be doing and try to narrow down exactly what isn't going right. This might include thinking about what a user should be doing, or what kind of test data the program should work for.
Check for spelling and syntax errors - One of the easiest ways to get an error when coding is to mistype something, or to not write something exactly how the computer expects it to be. Check over your spelling and punctuation, or ask someone else to cast their eye over it.
Make it break every time - Often with computers, the only way to solve the problem is to replicate the problem. Trying to work out how to make the error happen every time can help you spot why the error is occuring.
Keep track of what you change - Whilst trying to fix the error, keep track of what you're changing, and only change one thing at a time. This will make it easier to work out what is making the difference, and if you need to undo any changes.
Ask for help - Everyone has to ask for help when coding, whether it's sharing code with a friend/colleague or using online forums. Don't be afraid to ask someone else for advice or to see if they could spot the error. They might've had the same one in the past - many errors are common ones!
There's a wealth of information out there and sometimes it can be overwhelming to know where to look. There's a few different sites that can be useful to pick out of your search results when you're trying to solve coding problems.
The first place to look is the official documentation for the coding language or platform you're using. For example, if you're using Python you might want to try links to the documentation on www.python.org (or use their search feature), as that will get you information straight from the source. This can be useful when you need to know what a particular keyword or feature in the coding languages does.
Another key site for solving coding problems is Stack Overflow, a place for asking other people your coding problems and getting answers. Results from the site will often come up when you search for error messages, and though the replies can sometimes be varied, there's often useful information to be found. You can also go directly to the site and ask your own questions if you need.
Think about what you'd currently do if you had a technological problem that needed troubleshooting - do you tend to follow the same process?
The last time you had an IT issue, what did you do? How effective was it?
If these questions make you think you need some more help with troubleshooting, use the information on this page and links to other materials to think about what you could do differently, and then try putting it into practice next time you have an issue (in coding or otherwise).
There are a range of skills involved in troubleshooting coding problems. One skill is being able to use search engines effectively to find your answers. As well as searching for error messages, you might want to think about search techniques and how to evaluate sources of information - find out more on our Find & research Skills Guide pages.
Troubleshooting itself is a skill, and we have some guidance more broadly on how to analyse and solve problems with technology.