麻豆官网首页入口

What is a computer bug?

A mistake or error in an or computer is called a .

We know we have a bug when our computer programs don't work as expected.

They might be simple typing errors in the program or more serious problems in the order or sequence of the code.

They may even be errors that we made when we first organised our instructions into an algorithm.

When we find the bugs, we can correct them. This is called debugging.

Back to top

Checking for bugs as we go

Debugging is a very important part of writing a good algorithm or computer program and it works best when we check for bugs as we go along, rather than at the end.

Let's think about an everyday example, like writing a set of directions for your friend to get to the science museum.

The first part of solving this problem is to break it down.

  • Tell your friend the name of the museum, and what area it is in.
  • Find their address on a map.
  • Work out the quickest way to get from their house to the science museum.
  • Write it all down for your friend to send to their parent or guardian in a message.

You could make an error in any of these steps.

You might:

  • type the name of the park incorrectly
  • use an old address for your friend and start in the wrong place
  • pick a route that has been changed by a new building site
  • make a spelling mistake in the text you send them

A bug in any of these stages will end up with your friend being very lost so it's important to check each stage carefully.

Back to top

Watch: All about debugging

This film from 麻豆官网首页入口 Teach explains more about debugging.

Back to top

Bugs in a computer program

When we create a computer program to solve a problem or complete a task, we have a good idea of what we want to happen when the finished program is run. We know what the solution or outcome looks like.

If the outcome is NOT what we expected, or the program stops working altogether then we probably have a bug somewhere in our program.

Even if you check your algorithms and programs for bugs as you go along, some might still end up in the finished program.

Hungry Alien

You have just created a new computer game called Hungry Alien.

In the game, when you press the arrow keys on the keyboard, the main character - a hungry looking alien - moves around the screen collecting food.

Here is the code you have written to control the Hungry Alien character:

You share the finished game with your friends, but after they play you start getting messages saying the game doesn't work - oh no!

Back to top

Finding the bug

The best place to start is by remembering what you want to happen when the program is run. You want the alien to move when the arrow keys are pressed.

In the game the alien character did not move when the arrow keys were pressed.

It makes sense then to start debugging by looking at the section of the code that controls the alien character movement.

Can you spot the mistake in the code?

Back to top

Persevering

Debugging is an important part of learning to write algorithms and computer programs.

We need to check our algorithms and programs as we go along, rather than at the end.

We must keep on checking and testing until our program behaves in the way we planned, and we can complete the task or solve the problem we started with.

Back to top

Are bugs always bad?

Making mistakes, spotting and correcting them is an important part of learning for everyone.

This means that debugging our algorithms and programs can actually be helpful if it means we are trying out new ideas and challenging ourselves.

There will always be bugs to find. Checking for them and fixing them helps us become better at writing computer programs.

Look below to see the correct code.

Back to top

Activity: Quiz

Back to top

Computing - Dance Mat Typing. game

Build and test your computing skills with different levels of touch type challenges

Computing - Dance Mat Typing
Back to top

More on Computer science

Find out more by working through a topic