What is a program?

From Wikiversity
Jump to navigation Jump to search

Overview

[edit | edit source]

In this lesson we will discuss the different aspects of a program, the different form it may take and how it can be compiled such that a computer can understand and execute it.

Goals

[edit | edit source]

At the end of this lesson, the students will know the difference between an algorithm, a computer program and a compiled executable.

Of Humans, Computers and Programs

[edit | edit source]

A program is a collection of instructions that describe a task.

This rather simple definition can go a long way. Every recipe, for example, is a program. The instruction for assembling your favourite Ikea nighttable is a program. When you go to the theater, the actors on stage follow (hopefully) a program. Even for life in general we're constantly asked to "get with the program", whatever it is.

Humans are generally pretty flexible when it comes to interpreting programs. When the recipe tells us to slice the tomatoes it doesn't tell us how, or to use a knife. If we don't know that, we're probably better off not cooking in the first place and probably shouldn't be using knives anyway.

The limiting factor in the successful execution of programs is usually language and/or detail of the description.

If the recipient doesn't speak the language, no amount of hollering will get him or her to correctly perform the task you are describing -- even if that language is English. That's why Ikea likes to print its assembly instructions as pictograms -- the bar for correctly understanding images is much lower that that for correctly understanding Swedish.

Similarly, no amount of mastery of the Swedish language will get you around putting the wrong screws in the wrong holes (two wrongs don't make a right here -- there are more screws and holes than you think) if you are not told where they go. Simply printing an image of the finished nighttable won't get anybody anywhere -- which is why there is pretty much one image for each set of screws.

Given a set of decent instructions -- in a decent language and at a decent amount of detail -- is still, however, no guarantee that the human in charge of the nighttable won't mess it up anyway. That is so because, however flexible humans are at interpreting programs, they successfully compensate for it with laziness, inattention or plain ineptness.

This is why computers were developed. Computers are neither lazy, inattentive nor inept. They are able to perform a set of tasks blazingly fast. The limitation, however, is the same as for any human that can preform a task blazingly fast: they don't think. Therefore, in order for a computer to actually do something useful blazingly fast, we have to give it very, very detailed instructions. And since most computers don't speak Swedish, we have to give them these detailed instructions in a language they understand.

Computer Executables

[edit | edit source]

The language which a computer understands is generally called assembly language. This language consists of a very basic set of operations such as

  • Read a number from somewhere in memory
  • Multiply that number with some other number
  • Write the resulting number somewhere else in memory

As you may imagine, writing programs such as a web browser or the latest first-person shooter can be a somewhat long and tedious task. This is why programs are rarely written directly in assembly language -- they are usually written in computer programming languages and automatically translated (compiled) to assembly language.

Computer Programs

[edit | edit source]

What we usually refer to as computer programs are higher-level descriptions of what the computer should do

Algorithms

[edit | edit source]

algorithm ialah buto mak ko laa...aku tgh kuiz nih...

The Path from an Algorithm to an Executable

[edit | edit source]