perlsOfLondon

 

What do Computers Do

Page history last edited by dmlond 3 yrs ago

Computers run programs. There are different kinds of programs:

  1. System Applications: These are things like the operating system, which run the entire time the computer is on. They typically run with administrative privileges. Most people never write system programs.
  1. User Applications: These are programs that run at the request of the user. They may also run the entire time the computer is on, or they may only run during discreet user requested times, or as-needed by the user. In Linux, they do not normally have administrative privileges, so they cannot use up all the memory, overwrite critical system files, or files of other users, etc. These are the primary types of programs that users will write themselves.
  1. Packages (also known as Libraries): These are programs that dont actually run (they are not executable), but provide useful functions to be shared by many different applications.
What do Programs do?

Programs are like recipes. They are created to perform a specific task, involving the manipulation of some form of data, to produce more data. There is a wide variety of data which is handled by computer programs. Programs are written in a variety languages. Each of these languages has their own syntax, and rules. They are also, for the most part, not interoperable, e.g. you cant use a package written in C or C++ within a perl program (without special glue-code working between them, which we will not discuss in the class). However, almost all of the modern languages have a fairly similar syntax, which is much like a human readable document. Within a program, data is held in something called a variable. This is pretty much just like the thing with the same name in a mathematical equation:

y=2x+1

Here there are two variables. One, the dependant variable y, depends upon the other, independent variable x, to determine its value. The independent variable in this equation may be a dependant variable in another equation. Computer programs work the same way, except that their variables can hold strings, binary data (images, digitally encrypted notes, etc), as well as numbers. Also, remember to expand your definition of the mathematical variable to include matrices, and remember that computer variables can also hold more than one piece of information in things called arrays, and hashes (which are special arrays). In a computer language such as perl you could code the above equation as a statement:

$y = (2*$x)+1;

Here $y is called the 'lvalue', because it is on the 'l'eft side of the equals sign (the assignment operator). Its value is determined when the 'expression' on the right side of the assignment operator is 'evaluated' by the computer and the assignment operator instructs the data returned by the evaluation of that expression to be placed into the lvalue (really, the variable is tied to a piece of computer memory, called an address, but you dont have to really think about this much anymore).

Another thing that computers and mathematics have in common is the idea of a function. A function is an equation which can be 'plugged in' to another equation using a symbolic representation of the equation. Thus, you might have a function which computes the square of a given number defined by:
square(a) = a * a
And you could then write the equation to calculate the area of a circle given a particular radius as
A(r) = 2*pi*square(r)
Computers also allow you to use functions in your programs, which allow you to write a certain piece of complex code only once, to be reused over and over again within the same program.
sub square { my $a = shift; return $a * $a; }
my $l = 20;
my $area_of_circle = 2 * 3.154 * square($l);
my $area_of_square = square($l);
In fact, when you start working on the unix/linux commandline, you will realize that many application programs themselves can be used as functions, and 'plugged in' to a so-called 'pipeline' of other programs which produce a particular output given a particular input. This unix way of writing small, well specialist programs designed to be plugged into a pipeline fell out of favor a bit with the advent of the windows operating system, and its emphasis on all in one solutions. But with the advent of web services, it is quickly coming back into favor.

Comments (0)

You don't have permission to comment on this page.