What Is a Bug When the code you write has a problem we say that it has a bug It is actually pretty rare to write a piece of code and for it to work exactly how you want it to the first time Bugs are just a part of life for a coder It isn’t always the coder’s fault Sometimes the language you are using to write the code has a bug in it Debugging is what coders call it when they search through and find any problems in their code Sometimes a problem can be really obvious the minute you start to look Other times the bug can be quite difficult to find 1000100101001000 1101011000101101 0010100011101101 0100101101101100 1110100010110110 0010100101001000 1101011000101101 1000100101001000 0011000110000110 1011101011011010 Why are they called bugs One story claims that we use the word bug to describe these coding problems because a moth was found in an early computer at Harvard University However the word was used in electronics before that It may be short for bugbear or bugaboo which are old words to describe imaginary things that cause fear or concern such as goblins or spirits 4
What do coders do if they find a bug They change the code to fix it Then they test the code to see if their fix worked Debugging a piece of code can take time Sometimes a coder may need to repeat a set of steps over and over changing little elements each time until they get the result they want GET Programming How good are you at spotting mistakes Computers need really clear instructions to know how to do something They cannot think for themselves Can you see the mistake in these instructions telling you how to put your shoes and socks on What should the correct order be 1 Find shoes 2 Find socks 3 Put on shoes 4 Put on socks Answers are on page 32 5
How Do You Write Code Before you can work out what went wrong with your code you need to write some code So how do you tell a computer what to do You need to use a computer language that will translate your commands into something that the computer will understand Computers don’t understand most words or numbers the way that people do Computers use a number system known as binary Binary just uses two numbers 0 and 1 Every command that you give a computer is at some point translated into binary Don’t worry though the language that you use will do this for you How can 0 and 1 turn into commands Basically the language asks questions that just need an answer that is either yes or no or true or false 1 True or Yes and 0 False or No 6
GET Programming Think of a day-to-day task you could program a robot to do for you Maybe you want him to wash your dishes Your robot will need to test whether certain conditions are true or false What will you need to ask your robot to get the job done right Think of all the decisions that you have to make before you put the dishes in the sink Is this dish dirty True or False True Wash Dish False Don’t Wash Dish Is there food still on the dish True or False True Place Food in Trash then Wash Dish False Wash Dish Is the dish made from paper True or False True Don’t Wash Dish False Wash Dish Think of another task you could program a robot to do Then try writing it in True or False code 7