Main Page | See live article | Alphabetical index

Pascal programming language

The computer programming language Pascal is one of the landmark programming languages on which generations of students cut their teeth and variants of which are still widely used today. TeX and much of the original Macintosh operating system were written in Pascal.

The computer scientist Niklaus Wirth developed Pascal in 1970, in an effort to make structured programming easier for a compiler to process. Pascal is based on the Algol programming language and is named in honor of mathematician and philosopher Blaise Pascal. Wirth also developed Modula-2 and Oberon, languages similar to Pascal which also support object-oriented programming.

Table of contents
1 Basic Syntax
2 Pascal and C
3 for comparison. Because = effectively serves both purposes in mathematics, people often use that shorter symbol when the other one (either := in Pascal or
4 Implementations
5 Publicly available compilers
6 Past Criticism
7 Further reading
8 See also

Basic Syntax

A common example of a language's syntax is the Hello world program.

program HelloWorld;
begin
  WriteLn('Hello World!');
end.  

All programs start with the "Program" keyword, and a block of code is indicated with the "Begin" / "End" keywords. Case is ignored in the Pascal language. Semicolons separate statements, and the period ends the program (or unit). For some compilers the Program line is optional.

Pascal, in its original form, is a purely procedural language with the standard array of if, while, for, and related constructs.

Pascal and C

Pascal was developed around the same time as C, and there are important similarities between the two. Original Pascal and straight C are both small, procedural languages implementing structured programming concepts. Both have functionality for the dynamic allocation of memory and some form of pointer manipulation. But the languages have a distinctly different appearance, with C being much more terse.

One difference that is a source of holy wars is Pascal's use of := for assignment, with = used for comparison. This contrasts with C's use of = for assignment and

for comparison. Because = effectively serves both purposes in mathematics, people often use that shorter symbol when the other one (either := in Pascal or

in C) is really what is wanted. The designers of C argued that assignment is much more common than comparison, so that it should have the shorter symbol. Pascal supporters argue that accidentally making an assignment can be much more harmful than accidentally performing a comparison, which is certainly true if, as in C, an assignment is perfectly legal inside the test of an if statement.

This debate reflects the differences in design philosophy of the two languages. Pascal was designed, in part, as a teaching language. Error-prone constructs were carefully avoided, and an effort was made to make the syntax easy to understand. The authors of C placed more of an emphasis on brevity.

Another major difference is that Pascal is strongly typed. This means that all variables must be defined with a specific type before they can be used. Also, incompatible variable assignments are not allowed without an explicit type-cast. This prevents common errors where variables are used incorrectly because the type is unknown. It also alleviates the need for Hungarian notation - the practice of prefixing variable names with type-identifying letters.

Unlike C, Pascal permits nested function definitions. In its original form, Pascal lacked a mechanism for separate compilation or for handling arrays with a size unknown at compile time, but for decades versions of the language have been used that had alleviated or eliminated these problems.

Implementations

Early approaches (most notably the UCSD p-System) translated Pascal code into a machine-independent p-Code representation. This intermediate code was then interpreted by a program specific to each architecture. As a consequence, only the small interpreter part had to be ported to many architectures.

In the 1980s Anders Hejlsberg wrote the Blue Label Pascal compiler for the Nascom-2. Later he went to work for Borland and rewrote his compiler to become Turbo Pascal for the IBM PC. This new compiler sold for $49, which was much less than the price Hejlsberg originally asked for the Blue Label Pascal compiler.

The inexpensive Borland compiler had a large influence on the Pascal community that began concentrating mainly on the IBM PC in the late 1980s. Many PC hobbyists in search of a structured replacement for BASIC used this product. Turbo Pascal, being available only on one architecture, translated directly to Intel 8088 machine code, making it much faster than interpreted schemes.

During the 1990s compilers that could be re-targeted to different hardware architectures became more prevalent. This allowed for Pascal translation to native machine code that was at the same time easily ported to new hardware.

With Turbo Pascal version 5.5 Borland added object orientation to Pascal.

However, Borland later decided it wanted more elaborate object-oriented features, and started over in Delphi using the Object Pascal draft standard proposed by Apple as a basis. (This Apple draft isn't a formal standard yet.) Borland also called this Object Pascal in the first Delphi versions, but changed the name to Delphi programming language in later versions. The main changes compared to the older OOP extensions were a reference-based object model, virtual constructors and destructors, and properties. There are several other compilers implementing this dialect: see Delphi programming language.

Publicly available compilers

Several Pascal compilers are available for the use of general public:

Past Criticism

While very popular (although more so in the 1980s and early 1990s than at the time of writing), early versions of Pascal have been widely criticised for being unsuitable for "serious" use outside of teaching. Brian Kernighan, co-creator of the C programming language, outlined his most notable criticisms of Pascal as early as 1981, in his paper Why Pascal Is Not My Favorite Programming Language. Since that time Pascal has continued to evolve and most of his points do not apply to current implementations.

Many uninformed people still subscribe to the old belief that Pascal is not for "serious" programming and do not realize the benefits it currently offers. This stigma, more than any actual deficiency, is Pascal's biggest liability.

Further reading

See also