Pascal is a programming language designed by Professor Niklaus Wirth at the Swiss Federal Institute of Technology, and was introduced in 1970. He named the language after Blaise Pascal. Pascal is based on Algol, and it was intended as a sucessor to that language.

Pascal is a good example of a strongly typed, procedural, imperative programming language. Pascal was initially designed for teaching purposes, but found a use in industry, where it was soon extended with the extra features needed for real-world use.

As an interesting aside, an early Pascal (circa 1978) called UCSD Pascal was compiled to an intermediate code called p-code, which much like java decades later, was run upon a virtual machine for portability reasons.

The main languages derived from Pascal are Wirth's subsequent creations: Modula, Modula-2, Oberon and Component Pascal. Eiffel also owes much to Pascal. Pascal has also been influential on a number of languages, from ADA to Visual Basic.

All of Pascal's offshoots improve on the original Pascal, and arguably they are better even than the extended Pascal in common use. However none of them have had the mainstream success that Pascal, C and several C-derived languages such as C++, PHP and Java have had.

The most successful pascal implementation by far was Borland Turbo pascal, later Borland Delphi. This is a much-extended language, at one stage called Object Pascal. The original Pascal is mainly of historic interest now, but there is much Turbo Pascal and Delphi code in active use and development today.

For systems and applications work Pascal has largely been eclipsed by C and derived langauages. Pascal is very similar in concept to C. It was created around the same time as C, which saw the light of day in 1971. But where pascal was designed to be simple, structured, readable, and strongly typed, in order to promote good coding habits for teaching purposes; C was cooked up by a hacker busy coding an OS as a low-level, flexible assembler tool with a terse syntax, the freedom to do what you want and the responsibity to not shoot yourself in the foot in the process. Despite this, they are similar languages, and have grown closer over the years.

The most obvious syntactic differences between (a version of) Pascal and the C family of languages are discussed here.

A short Pascal links list

The programming language:
Niklaus Wirth Pascal: User Manual and Report
pascal string When to use a semicolon in Pascal Differences between C and Borland Delphi Pascal to C Converter.
Opinions of the language:
Why Pascal Is Not My Favorite Programming Language, Why I love Pascal so much, Why Pascal Sucks
Related languages:
Borland Turbo Pascal Delphi Object Pascal
Algol Modula Modula-2 Oberon Component Pascal Eiffel

Blaise Pascal: Pascal's theorem Pascal's Triangle Pascal on Diversions
Pascal's wager Flaws with Pascal's Wager Pascal's Wager and cult philosophy

Hello world in pascal

This should compile in original-spec pascal compilers:

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

The following compiles as a delphi 7 console application. However it uses no major delphi-isms:

program HelloWorld;

{$APPTYPE CONSOLE}

begin
  writeln('Hello World')
end.

Because this doesn't really give a flavour of the language, here is a longer example. This one uses some mild Delphi-isms (in particular the uses keyword to include other code units, the Result variable, and the semicolons after the final statements in blocks) and will probably not compile unaltered on other pascals.

program Cubes;

{ the sysutils unit contains the IntToStr function }
uses SysUtils;

{$APPTYPE CONSOLE}

{ SF 26 April 2003
  This contrived little program
  displays cubes of numbers 1-10
  And thereby demonstrates:
  - The difference between function and procedure
  - parameters and local variables
  - For loop
  - a gratutuitous if statement
  - oh, and the bits in braces, like this, are comments
  }

const
  MAX_CUBES = 10;

function Cubed(value: integer): integer;
begin
  if value = 0 then
    Result := 0
  else
    Result := value * value * value;
end;

procedure ShowCubes;
var
  liLoop, liValue: integer;
  lsMessage: string;
begin
  for liLoop := 1 to MAX_CUBES do
  begin
    liValue := Cubed(liLoop);
    lsMessage := IntToStr(liLoop) + ' cubed is ' + IntToStr(liValue);
    writeln(lsMessage);
  end;
end;

{ main program }
begin
  ShowCubes;
end.

Now for some writeup-as-reply.

Mcc says: Pascal is basically C
Pascal was originally intended as a teaching language, whereas C started life as a better assember for OS hackers, so there will be differences due to design objectives as well.

Pascal has a word in uppercase letters
Pascal is case-insensitive. I much prefer the convention of reserved words all in lower case, identifiers in CamelCaps.

unbelievably wordy syntax ...Pascal is very, very readable
Think about those statements. Both at the same time. Grok the fullness that Pascal's design objectives gave higher priority to readability than C, and lower priory to minimum-keystrokes than C. Many of C's features (e.g. use of { and }, the legality of statements like a = b = ++c; are designed to minimise RSI.

Now ask yourself, in these latter days, which is more expensive, hard disk space for the verbose source code or programmers spending time puzzling out obscure code.

Consider that long keyword or short keywords don't affect the executable size in any way, and that all the source code that you will ever write put together is probably smaller than your mp3 collection by a factor of ten. Consider that a decent development environment can save you a lot of the typing. This isn't the 70s any more.

Admittedly C's bit-twiddling and byte groveling makes it a better tool for writing OSs and device drivers than pascal. Right tool for the job I say.

These days Pascal is not a suitable application development language any more than ANSI C is. Heck no, get an Object-Oriented language. Use Delphi.


Everyone quotes the Jagon file:
I find the writeup regarding Kernighan's Why Pascal Is Not My Favorite Programming Language annoying (see that node for further complaining).

It may be correct with regards to standard pascal, but the claim that "its criticisms are still apposite to Pascal itself after ten years of improvement" is rubbish. It is certainly not relevant to Object Pascal, the pascal-descended languages in use today.


Thanks to Ariels, Professor Pi and Gorgonzola for corrections, facts and opinions.