A magazine where the digital world meets the real world.
On the web
- Home
- Browse by date
- Browse by topic
- Enter the maze
- Follow our blog
- Follow us on Twitter
- Resources for teachers
- Subscribe
In print
What is cs4fn?
- About us
- Contact us
- Partners
- Privacy and cookies
- Copyright and contributions
- Links to other fun sites
- Complete our questionnaire, give us feedback
Search:
Programming FUNdamentals
Programming is a core activity of computer science. It is a skill for creation. Once you can do it, the sky's the limit over what you can make computers do. A program is just a plan of action a machine can follow. From such plans comes everything the computers you see around you do.
So how do you write a plan of action? It has to be written in a precise language, so that there can be no confusion as to what is meant. Everyone has to agree about what any instruction does. Different programming languages have different kinds of actions you can use as basic. They also have different ways of putting them in order. If followed in the prescribed order they should get the job done. Without fail.
Write your first program: an Artificial Intelligence (AI)
Let us start with something simple: beating humans at their own game. First you get to play a little AI we wrote that plays Noughts and Crosses (Tic-Tac-Toe). Then you get to write a little program of your own. The programming language you use is one where the actions possible are different kinds of Noughts and Crosses moves.
Play Noughts and Crosses. Write your first programPrograms are like ...
Programs are like recipes
The chef who writes them tries to write the instructions clearly enough that anyone can follow them. They tell you the actions (stir vigorously) and the order to do things. (no point baking first then, stirring vigorously). Recipe book languages are not precise enough though. My cakes still come out burnt or soggy. What exactly did "until firm" mean? We have to do better than cookery book writers.
Programs are like musical scores
When a composer writes a musical score they are doing something very similar to programming. Just as with programming complex notations have been developed for writing music. The actions are now just to play specific notes in a given order. Assuming the musician is skillful enough to follow the instructions in the score, the music will sound the same every time it is played. Mind you there is still room for interpretation. Great musicians go beyond the score, putting in feeling. The other thing about musical notation is that it is only a language for making music. Our noughts and crosses language was similarly only a language for writing noughts and crosses programs, nothing more. We want languages that allow us to write programs to do anything.
Programs are like Game Show Formats
When a new TV game show is commissioned, the format has to be designed and written up in a game book. It outlines the actions that are taken by the host and players at each point in the game and that is much like a program too. Write it in a programming language and you would have the basics of an online version of the game show. In the noughts and crosses game, we gave you lots of help by using a very powerful language - the actions did big things in one go. For a general language we need instructions and ways of putting them together that are the essence of plans of whatever kind. Game shows are a good way to see how to develop such a language.
Work through the design of a new game showOnce you have worked through it, have a go at inventing your own game show, and write it up using a similar language.
Programs as objects
There are lots of ways of thinking about programming. The different ways lead to different kinds of programming language. So far we have been thinking of programs as being sequences of actions to follow - a recipe. Another way of thinking of a program is as a description of lots of objects or agents that have behaviours (things they can each do) and properties (things about them that tell them apart). These objects send signals to each other to get things done they can't do alone or to tell another it is their turn.
Programs for Game Show Judges
Once you start thinking about programs as collections of objects you are moving to being an object-oriented programmer. Think about game shows again. There are contestants, judges, hosts. Each waits for their turn then follows the parts of the rules that applies to them. Judges think of scores and announce them, hosts asks questions and announce answers. Contestants answer questions or perform. They are all just "objects". Control passes from one to another according to the rules and the signals between them such as the host asking the judge for their score.
Create some judges. Describe some objects.Once you have worked through it, have a go at inventing the competitors of a game show and write them up using a similar language.
Functional Programming
We've looked at two different ways of thinking about programs above. Another way of thinking about them that is based more directly on mathematical reasoning gives a family of languages known as "functional programming languages".
If you want to try some functional programming visit the University of Oxford's GeomLab site. It is a great way to learn about this different style of programming by drawing pictures: even ones as complicated as Escher's beautiful, thought-provoking pictures with ever-repeating lizards, fish and other animals that you may have come across. You will also get an idea of the issues in laying out the elements of web pages like this one. Programs do that too.