Design

Designing your program

Before we make anything – a house, a dress or a computer program – we should start with a design. Because there are two important parts to most programs – the interface (how it looks) and the code – we design these separately.

● The easiest way to design the interface is by sketching it out on paper. ● To design the code, write out a list of steps it will have to perform in English. This is known as an algorithm and is just like the steps in a food recipe.

Solving problems like this is what programming is really about, rather than entering commands on the computer.

All good programmers design algorithms before starting to code!

repeat forever if right arrow key is pressed point right move 5 steps if left arrow key is pressed point left move 5 steps if up arrow key is pressed point up move 5 steps <span style="font-family: 'Comic Sans MS',cursive; font-size: 120%;">if down arrow key is pressed <span style="font-family: 'Comic Sans MS',cursive; font-size: 120%;">point down <span style="font-family: 'Comic Sans MS',cursive; font-size: 120%;">move 5 steps <span style="font-family: 'Comic Sans MS',cursive; font-size: 120%;">if explorer touches the same colour as the maze wall <span style="font-family: 'Comic Sans MS',cursive; font-size: 120%;">go back to starting position || || <span style="font-family: 'Comic Sans MS',cursive; font-size: 140%;">The table above shows an algorithm on the left for moving the explorer and Scratch code on the right that does the same thing. <span style="font-family: 'Comic Sans MS',cursive; font-size: 140%;">Algorithms let programmers concentrate on what the program has to do instead of how to do it on the computer. Once the algorithm is worked out, writing the code is easy!
 * <span style="display: block; font-family: 'comic sans ms',cursive; font-size: 140%; text-align: center;">Algorithm for moving explorer || <span style="display: block; font-family: 'comic sans ms',cursive; font-size: 140%; text-align: center;">Code ||
 * <span style="font-family: 'Comic Sans MS',cursive; font-size: 120%;">when the flag is clicked