Recent Articles



































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 Swiss computer scientist Niklaus Wirth developed Pascal in 1970, first as a hypothetical language that would encourage students to write structured code. 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.

[Top]

Overview

All Pascal programs start with the "Program" keyword, an optional list of internal filedescriptors and then a block of code is indicated with the "Begin" / "End" keywords. Letter case is ignored in the Pascal language. Semicolons separate statements, and the full stop 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.

Turbo Pascal, and other derivatives with units or module concepts are modular languages. Turbo Pascal copied these concepts from either a draft of the Extended Pascal standard or Pascal's successor Modula-2, however doesn't provide a nested module concept.

[Top]

Hello World

program HelloWorld(input,output); begin Writeln('Hello, World!'); end.

Notes: It is not nessesary to add 'input,output'

[Top]

Pascal and C

Pascal was developed about the same time as C, and there are important similarities between the two. Both were strongly influenced by Algol 60 and incorporate many of its essential features, including its block structure and type system, although the approach to type safety is quite different.

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. However, they 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 intended. The designers of C argued that assignment is much more common than comparison, so 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 emphasis on brevity.

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.

[Top]

Implementations

Early approaches (most notably the UCSD p-System compiler, based on the Zürich P4 compiler, both of which were written in Pascal itself) 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.95, 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.

Super Pascal was a variant which added non-numeric labels, a return statement and expressions as names of types.

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 additions 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.

[Top]

Publicly available compilers

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

[Top]

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 . On the other hand, many major development efforts in the 1980s, such as for the Apple Lisa and Macintosh, heavily depended on Pascal. In the decades since then, Pascal has continued to evolve and most of his points do not apply to current implementations. Unfortunately, most of the extensions to fix these issues are incompatible from compiler to compiler.

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

[Top]

Further reading

[Top]

See also












  View Live Article   This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License