This entry is designed to introduce the beginnner to the areas involved in programming. And to lead on to entries that introduce common aspects of programming which then direct you to language specific entries on that area.
What is Programming?
Put simply, programming is just telling a computer what you want it to do. But this isn't as easy as it sounds.
Programming is like trying to tell a very logical alien, who knows no human languages, how to make a cup of tea. When the alien has no concept of tea, cups, sugar, milk, water and kettles and they don't recognise the words you use for their arms, hands, and eyes or any of the relations between them.
Now through a complex series of cross cultural mime [This part is only necessary for this example] you have to design a language that is close to your own but can be easily translated into the aliens language. After that, as long as you explain clearly and methodically what things are, how things work, and what the alien needs to do, you should eventually get a cup of tea. On the other hand, if your explanations are unclear, ambiguous, incomplete or untranslatable you could end up with a kitchen awash with tepid water... and possibly a dead alien.
What is a program?
A computer program is a very detailed and precise set of instructions that tell a computer how to perform a task. Now the design then creation of this set of instructions for a task (a Program), and the removal of errors(bugs) involves four main stages:
There are four steps involved in writing a computer program:
1) Define the task the program is being designed to perform
2) Express the instructions in a suitable programming language.
3) Translate the program into code that the computer understands.
4) Do a test run, find the errors in the code, and remove the errors [Debug the Program].
These four steps are discussed in more detail below, along with the effect of errors in such a instruction based plan. These errors are called bugs; these can be failures in interpretation of instructions, or simply badly written instructions. These errors can lead to the program not working at all or carrying out a task different from that intended. However, unlike in the alien example above, bugs do not usually result in damage to the computer itself, but have been known to damage users1.
Tasks for computers
Now there is a wide range of tasks that a computer can perform, within reason. In effect if a need is there that can be filled by a programmed device, be that device a PC or a specialised type of programmable device, someone will be asked to write a program for it.
Now programs [also known as software] tend to come in 2 types:
System Software This type of software is concerned with telling the system how to use parts of itself or to organise and co-ordinate the system as a whole. For example drivers for graphics or sound cards for a PC [how to use parts] and the Linux OS2 [co-ordinate and organise].
Application Software This type of software is concerned with applying a device to a task. For example a word processing program is an application as it applys you PC to the task of word processing.
So what is the best way to define the tasks we ask computers to perform? In all probability the best way is to look at the mind boggling array of uses we have for computers and programming in the world around us.
What is Programming used for?
Well it depends on what people want to use it for, but it can be used for the following examples, but really the uses are only limited by developers imagination:
- To Create Systems to Deal with Repetitive Tasks
- To Create Systems to help Organise Data
- To Create Expert Systems(e.g. Diagnosis Programs, computerised researchers, etc.)
- Amusement, in fact there is a mind-boggling amount of computing used for amusement, from web sites, the internet, arcade games, VR consoles, Web Radio, TV, Games Consoles, and simulators of all varieties.
- Applications, now by this I mean tools and resources, for example Word Processors, and the whole H2G2 site.
- Invisibles, this is rather a blanket term, it covers everything that doesn't say "Hello! I'm a Computer", it includes things you might expect (e.g. Video Recorders, Robots) and some things you wouldn't (e.g. Washing machines, fridges, and even pens [in the case of digital voice recording pens]). These all include programming, although it is mainly compiled onto chips and wired into an electronic circuit. These programs stretch from very simple (e.g. Keep the fridge cold) to mind-bogglingly complex (e.g. work out the 3D location of an object, based on a pattern identifier working from images from two differently positioned cameras, and then move a robotic arm to meet the object).
Why are there Programming Languages? Why can't it be written in natural language?
There is a good reason for this, computers can only deal with data in a very basic way and the tasks computers perform must be broken down into a series of very simple actions. These actions are based upon the operations a computer can perform, which tend to break down into the following categories:
- Move data around in memory.
- Take in data from an external device.
- Give out data to an external device.
- Store and retrieve data.
- Compare two data values and say whether they are equal, or how they are not equal.
- Arithmetic Operations: Add, Subtract, multiply, divide, Increase by one (increment), Decrease by one (decrement) [These tend to be very fast operations]
Each task the computer has to perform is based on simple actions using these operations. These actions must be described very precisely and natural language is not suited to this task. A good way to illustrate the computers need to have a task defined as a precise ordered set of actions is to look at how the CPU reads a Program.
The problems in using natural language are very clear if you try to think about a seemingly precise instruction in natural language from the computers perspective. For example "Take the Davies file to Personnel!" is a perfectly clear and precise natural language instruction to a person. But that instruction would leave the computer with the questions, "Where is the file?", "Where is personnel?", "How do I move the File there?", "Where am I?", "What am I?", more questions on the detailed nature of the file and finally pleading for an explanation of the concept of time. And alternatively if traditional computer programs were written in natural language they would be very long and complex and full of details that another human would find unnecessary.
Programming languages are designed to bridge this gap between human thought and computers. It does this by being clear in its meaning to the human mind but also, after simple translation, to have meaning to the computer.
There are four generations of programming language and many different languages within each generation.
|4th Generation Languages||MATLAB, Mathcad,||[Closer to Human Language than Computer Language]|
|3rd Generation Languages||FORTRAN, The C Programming Language, C++|
|2nd Generation Language||Assembly Language||[Closer to Computer Language than Human Language]|
|1st Generation Language||Machine Code [Binary]||[Computer Language]|
However many of these languages have concepts in common and one of the purposes of this project is to explain some of these concepts.
Common Programming Concepts
Programming is used to explain to a computer in terms it understands, exactly what you want it to do, to what variable and the nature of the variable. Now this means that there are a lot of overlaps between different programming languages. In this section we will work out exactly where those overlaps are, and lead to entries on general definitions of how these aspects of a program work.
Now the best way to define these overlaps is to look at what programming is used to define, in terms of the tea making alien, it is used to define the following:
1) What data is involved and what the data is.
(e.g. cup, kettle, water, tea, sugar, milk, visual input, arm, hand)
2) What is the process of the program, in other words, what series of events happens (i.e. what series of instructions to execute), in what case, and in what order.
[ Conditional statements, programming Loops, Variable Manipulation]
(e.g. Put water in Kettle, Turn on Kettle, put tea in cup, put sugar in cup, when water boiled put in cup, add milk, remove tea )
Now these aspects are the basis for most program code. They allow you to convert things from a natural language idea into a programming language structure.
How do these Common Programming Concepts work to create a program?
The best way to show you is with an example. The following is a program in natural language, in other words the way that we would speak:
|[STEP 1]||[STEP 2]||[STEP 3]||[STEP 4]|
|The postman goes to the gate of each house.||If there is a letter for the house he goes to the door and posts the letter through the letter box.||If there is no letter for the house, he goes to the next house.||This continues until there are no more letters for the street.|
This in fact displays obviously two of the main concepts in programming, Conditional statements3 and loops4. These are also fundemental aspects of human thought, conditional statements[e.g. IF statements] and actions we repeat[loops]. These and other common aspects allow programmers to outline concepts in human thought within a framework the computer can use.
The next stage is the breaking down of the natural language program into a series of simple operations based upon the code of a programming language. This is basically the construction of an detailed Algorithum for the computer to define the task in the form of the programming language. Where it is understandable to the programmer, but it takes on more computer like qualities. However it is worth noting the code still unusable by the computer in that form.
Now to explain some of the conversion, I will use an made up programming form to show you the general points. I repeat This is NOT a Programming Language Example, it is mearly a useful guide to the application of the common programming aspects to a program [If there are any aspects used that you are unclear on a link has been provided to the explaining entry].
|STEP 1||Define Variables [integer]:||current_address, current_letter_address, number_letter_remain:||set start value to 0;|
|STEP 2||Define Variable [Boolean]:||letter_delivered:||set start value to "FALSE";|
|STEP 3||Get values for||current_letter_address and number_letter_remain||from external device [Postbag];|
|STEP 4||Get value for||current_address||from external device [Eyes];|
|STEP 5||WHILE||(number_letter_remain NOT EQUAL TO 0)||Start of Loop 1|
|STEP 6||WHILE||(letter_delivered EQUALS "FALSE")||Start of Loop 2|
|STEP 7||IF||(current_address LESS THAN current_letter_address)||Increase current_address by 1|
|STEP 8||ELSE IF||(current_address GREATER THAN current_letter_address)||Decrease current_address by 1|
|STEP 9>||ELSE IF||(current_address EQUAL TO current_letter_address)||Deliver Letter and set letter_delivered to "TRUE"|
|STEP 10||END OF LOOP 2|
|STEP 11||number_letter_remain||= number_letters_remain - 1|
|STEP 12||Get value for||current_letter_address||from external device [Postbag];|
|STEP 13||END OF LOOP 1|
The above fake programming language example shows how we can construct a program to work on a task based upon these building blocks which are common to most programming languages. However we have to remember there are variations in how to use these common concepts between languages, for example what they are called and how they are used.5
Now this is all well and good, but we have to remember that there are many different things to keep in mind when writing a program aside from the task itself. It is very rare to find a person who can write successful code instinctively, so over time methods of best practice have developed. Some of the aspects of best programming practice are covered in the seven secrets of a successful programmer.
After we create a programming language program we have to move on to translating the programming language program into computer code6.
Which is understandable to the computer and is as small as possible so as help the program to run7 effectively.