Some elements of languages include symbols, such as the + sign. Others contain
actual words, such as print. Others include pseudo-English, such as fprintf,
which in the C programming language means, print something to a file (the first
f) in a particular format (the second f). Here is an example of a function in
the C programming language which marks the pixels in an image that fall within
certain color ranges (in particular, this is part of a face-detection program):
void MarkSkin( rgbimage *image, int marker ) {
int i, j;
for ( i = 0 ; i < image->ydim; i++ )
for ( j = 0; j < image->xdim; j++ ) {
if ( ( image->r[i][j] >= MIN_RED && image->r[i][j] <= MAX_RED ) &&
( image->g[i][j] >= MIN_GREEN && image->g[i][j] <= MAX_GREEN ) &&
( image->b[i][j] >= MIN_BLUE && image->b[i][j] <= MAX_BLUE ))
image->r[i][j] = image->g[i][j] = image->b[i][j] = marker;
}
}
|
(Basically, it tells the computer to go through each row and column of the image, examine the red, green, and blue values of the each pixel, and, if they fall within certain ranges, then set them to a marker value.)
You have probably heard the names of some computer languages. Common languages include Assembly, BASIC, C, FORTRAN, Java, LISP, Pascal, Prolog, and Visual C++. There are many more. Why are there so many languages? The reason is that different people designed the different languages, often with a particular purpose in mind. Accordingly, some languages are more efficient than others for directing the computer to do certain kinds of tasks. Also, as hardware has gotten faster and memory cheaper, computer languages have adapted. Finally, computer-science theorists tweak and redesign languages to make them better able to express complex ideas and more efficiently communicate tasks to be performed.
Does an ordinary computer user need to know a computer language? Perhaps not, but it does lead to a deeper understanding of how computers work, and knowledge of PHP in particular may become valuable as more and more businesses and individuals express themselves through web pages.
Computer languages are classified into several categories:
PHP, as we will see, combines elements of functional and imperative languages.
When a programmer writes something in a computer language, the resulting text document is called source code. However, a computer cannot understand text, but only numbers. Accordingly, the source code must be translated into commands that a computer processor can understand. The translation is done by one of two types of computer programs:
Most programs written for Windows, the Macintosh operating system, or UNIX, are distributed as executable code. For example, the program files for Microsoft Word or Adobe Photoshop consist of binary numbers: CPU instructions and related data. Thus, you don't have to run an interpreter in addition to the program you want to run. Moreover, it would be very difficult to figure out how Word was programmed by examining the executable code, so Microsoft's trade secrets are secure.
PHP programs are interpreted. In the case of PHP, the interpreter is part of the web server. Since the web server is running already, there isn't a lot of additional overhead in interpreting PHP. Moreover, PHP programs tend to be relatively short, so the kind of optimization that compilers do would be unlikely to improve performance significantly. Also, not having to recompile each time you make a small change to a PHP program makes it much easier to maintain a web site.
The Open Source Software Movement promotes supplying source code along
with executable programs. Accordingly, Linux, and programs that run on Linux,
are distributed with their source code. This means that a sophisticated user
can tweak the code and recompile the operating system and applications to customize
them. Distribution of source code also has the benefit in that the code is made
public, and mistakes in the code are usually quickly identified. This is one
of the main reasons Linux is considered to be more robust than Windows.