Computer science is no more about computers than astronomy is about telescopes. -Michael Fellows
By analogy, computer science is no more about programming than astronomy is about adjusting dials on telescopes. Astronomy is more than the art and science of operating a telescope!
All the same, any serious student of astronomy will benefit from a bit of skill with telescopes and their various dials. Similarly, programming is a fundamental skill in computer science, and understanding how it works is helpful if you want to gain a deep understanding of computer science.
A program is a series of instructions that a machine can perform. A machine might be a computer, or it might be your brand-new DeliverBee Drone.
In this exploration, you'll help your DeliverBee Drone deliver packages by writing simple programs.
The program below is a sequence containing three instructions, the boxes with arrows pointing towards the east (the right side of the screen). Press “Run Code” to watch the DeliverBee Drone go east from the short red house until it crashes into a tree.
Once the drone crashes, press the Reset button. This will restore the drone to its original position.
After clicking Reset, the program can be modified. Click and drag the first instruction away so only two instructions remain.
What happens if you drag away the leftmost instruction, leaving the two other instructions, and then re-run the program?
A program is made up of instructions that can be understood both by humans and computers. Humans need to understand the instructions in order to read, write, and share programs. Computers need to understand the instructions in order to bring the programs to life by running them.
In this example, you have only two instructions available, though you can use them as many times as you want. (Drag instructions from the top bar down onto the program.) The two instructions tell the DeliverBee Drone to go north (up) and east (right).
The program that is there now will guide the drone to the square blue house. Which of the other houses are reachable?
The sequence of instructions that you give our DeliverBee Drone is a stored program. After you write the program down once, the drone can execute those instructions again and again. Being able to repeat a set of instructions again and again is part of what makes automation powerful!
The very first stored program ever executed was written for an experimental computer called the Manchester Baby. The program was seventeen instructions long, which was important because the computer could only store thirty-two instructions!
Modern computers seem like they can hold an endless number of instructions compared to primitive computers like the Manchester Baby. Nevertheless, computer scientists will always find themselves running into limitations, because computer science is, in part, about interacting with a complex world using limited options and finite storage.
Your DeliverBee is even more ridiculously limited than the Manchester Baby: it can only hold five instructions!
The instructions given guide the DeliverBee to the square blue house. Which of the other houses can you reach with 5 instructions or fewer?
(Remember: you can use each of the four instructions multiple times.)
So far, your programs have been very, very simple: the DeliverBee Drone has just executed one simple instruction at a time. Computer programs get more interesting when you can repeat instructions multiple times.
Press 'Run Code' to see the repetition instruction in action. The instruction contains a counter and takes the alternate path until its counter hits zero.
Without this new repetition instruction, how many basic directional instructions (North, South, East, or West) would your DeliverBee need to get to the square blue house?
Repetition instructions allow you to make better use of limited space, but they also make programs a great deal more complex!
You can add a repetition instruction by dragging it on the program and then clicking at the position where you want the alternate path to go.
These instructions again guide the DeliverBee to the square blue house. With our extra instruction for allowing us to repeat a list of instructions, which of the other houses above can you reach?
A program is a specific set of instructions that can be executed by a computer. The instructions below are a program that gets the drone to the square blue house.
You can also call this program an algorithm: it's a specific procedure you can follow to achieve a goal in a systematic fashion.
Sometimes, when computer scientists talk about algorithms, they are referring to a precise description of an automatic process that is tuned for human communication and not understandable by a computer. An algorithm does not necessarily need to be something that can be immediately executed by a computer.
Here's a description of what the program above does: “Have the drone go north and then east, and then repeat that three more times. Finally, go east and then south once.” Those two sentences are certainly not a program, but they are an extremely simple algorithm.
When a precise English description of a process and a program communicate the same process, you can say that the specific program is implementing the algorithm.
Which algorithm does this program implement?
You've now explored programming as a way of automating a DeliveryBee drone to perform a very specific delivery task.
These tiny programs have only presented the smallest glimpse of what programs and algorithms can do. Explorations in the following chapters will cover many more possibilities!
In particular, your programs solved very specific problems, navigating the drone through a specific grid. Many algorithms solve more general tasks, and can make decisions that the programmer didn't completely describe ahead of time.
One example is route-finding on a map. Given the drone's position, its desired destination, and a map, it's possible for an algorithm to actually find the correct instructions for getting to the destination. That's an algorithm writing an algorithm!
Another example is navigating in an uncertain environment. If our delivery drone doesn't have a perfect map of all obstacles ahead of time, then you can write a program that takes inputs from its sensors and turns them into movements that try to guide the drone towards the goal.