"Wirth made a language acclaimed in theory, but useless in practice. He appropriately named it after the guy who came up with "Pascal's Wager". --anonymous

Note that the following refers to the original Pascal language. Several Pascal derivatives have arisen that are much more complex, and actually have compelling language features beyond what C++ offers. I have not used these; See delphi, or strawberryfrog's excellent writeups on Object Pascal.

Pascal is basically C, except everywhere C has a symbol, Pascal has a word. Also, strings are a built-in type. That's about it. The two languages are so similar that you can literally translate mechanically between them. I mean, I'm sure that somewhere, somehow, there's a couple of things that Pascal does for you that are nice, but from what i've seen i seriously doubt they could be worth the extra typing of the unbelievably wordy syntax. And personally i suspect that the things it does for you are going to turn out to be the kinds of things that are really much more convenient as optional, replaceable libraries (or packages or whatever) added as add-ons written within the context of the language, rather than things hard-wired into the language itself.

I do not know Pascal, but i have had to deal with Pascal a decent amount, since i am a mac os programmer and all of apple's documentation gives all sample code in Pascal. While this sounds odd at first, it's actually pretty reasonable-- Pascal is very, very readable.

Giving sample code in C seems like a good idea, but think about it; not everyone is going to know C, not everyone using apple's API will be doing so in C, not everyone is going to look at and understand C. But pascal, you don't need to know it; because it's mostly just english, you can understand everything the code does just by looking at it, even if you've never used the language before. Giving sample code in a pseudocode-like language is a pretty logical thing to do if you're trying to demonstrate something which exists independently of any one language, and Pascal was at one time often the language chosen for that purpose. (These days people doing that sometimes tend to use python instead).

While i probably should not be commenting on something i haven't used, out of what i've seen of Pascal, i have not seen a single reason to desire using the language for any reason. Pascal seems to me to be nothing more seriously than exactly the thing it was designed to be: A teaching language.

"pascal" is, by the way, a reserved word in C. A function can be declared as a pascal function (pascal void something() {}) and it will act when compiled in a way consistent with Pascal functions. I'm not totally certain what exactly this does, and cannot locate any documentation on it. Being declared Pascal has certain implications in terms of the internal structure of the compiled function, and in terms of how the variables being passed to the function are treated. There was a time when you often saw functions declared as pascal in things like libraries-- not every programming language can call C functions within a library, but quite a few more can call pascal functions within a library.

StrawberryFrog: Thank you.
I was not attempting to say that "everywhere c has a symbol, pascal has a word" is an inherently bad thing; only that it is true, and that i for one prefer otherwise.
I think you're probably right about the pascal keyword, however keep in mind that it can also be used to link _out_ as well as in-- i.e. to pascal and pascal-linkable languages.

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.

This is the genealogy of the programming language Pascal:

Pascal is a child of Algol W.
Pascal was first known as Pascal in year 1970.
Then it begat Modula in year 1975.
Then it begat Ada in year 1979.
It became Pascal ISO 7185 (Unextended Pascal) in year 1983.
Then it begat Turbo Pascal in year 1983.
Then it begat Object Pascal in year 1985.
Then it begat Perl in year 1987.
It became Pascal ISO 10206 (Extended Pascal) in year 1989, and has not changed much since that time.

This genealogy is brought to you by the Programming Languages Genealogy Project. Please send comments to thbz.

Its true that for most kinds of programming it is a lot more painful to program in Pascal than in C/C++. However the main reason here is not that the syntax is wordy. This is something that can easily be got over with any editor that allows macros. The point is that Pascal enforces a lot more discipline on the programmer. You cannot use a character and an integer interchangeably for example. Floating point overflows will cause runtime errors and so on.

Most of us love being indisciplined so Pascal is a no no language. However when doing Mathematical Computing, it helps to have a language like this because you know what is going wrong. A array index beyond bounds will cause a runtime error. The program wont just keep executing as if nothing happened and it is this discipline that makes Pascal nice.

Under parameter, rp was unsure how Pascal referred to its subroutines, functions, procedures, or whatever they were called.

Pascal has two types of what most 'normal' programming languages* call the same thing...

function UpCaseStr(S: string): string;
var
  I: Integer;
begin
  for I := 1 to Length(S) do
  if (S[I] >= 'a') and (S[I] <= 'z') then
  Dec(S[I], 32);
  UpCaseStr := S;
end;

begin
  writeln UpCaseStr("AbCdEfGhIj");
end;
This code fragment (partially borrowed from the Delphi 2.0 online help for function) displays what a function does. It returns a single value, and allows the function to be called in-line, allowing ease of coding. The S is a parameter passed to the function.

procedure NumString(N: Integer; var S: string);
var
  V: Integer;
begin
  V := Abs(N);
  S := '';
  repeat
    S := Chr(N mod 10 + Ord('0')) + S;
    N := N div 10;
  until N = 0;
  if N < 0 then
    S := '-' + S;
end;

var MyString:string;

begin
  NumString(8,MyString);
  writeln "That number, "+MyString+", is now a string.";
end;
This code fragment shows how a procedure differs. Firstly, it cannot be called inline. Secondly, it shows the difference between the two parameters. The first, the number, is a value parameter: only the value is sent to the procedure, as the parameter was in the function. The second, the string, is a reference parameter: the location of the string in memory (and thus the actual string itself) is passed to the procedure.

Personally, I feel this is a poor example of the ability of a procedure, since it has one reference parameter/output, and could have been coded as

function NumString(N: Integer;):string;
var
  V: Integer;
  S: string;
begin
  V := Abs(N);
  S := '';
  repeat
    S := Chr(N mod 10 + Ord('0')) + S;
    N := N div 10;
  until N = 0;
  if N < 0 then
    S := '-' + S;
  NumString:=S;
end;

begin
  print "That number, "+NumString(8)+", is now a string.";
end;
. Procedures are better in many cases, since you have more control over it: you can have multiple outputs, an input that changes, or no output at all. But functions are much neater.

*: QBasic uses subroutines and functions. That isn't a normal programming language at all.

Thanks to gorgonzola who pointed out that its write or writeln in pascal, not print... I'm in perl mode again!

parse = P = pastie

Pascal n.

An Algol-descended language designed by Niklaus Wirth on the CDC 6600 around 1967-68 as an instructional tool for elementary programming. This language, designed primarily to keep students from shooting themselves in the foot and thus extremely restrictive from a general-purpose-programming point of view, was later promoted as a general-purpose tool and, in fact, became the ancestor of a large family of languages including Modula-2 and Ada (see also bondage-and-discipline language). The hackish point of view on Pascal was probably best summed up by a devastating (and, in its deadpan way, screamingly funny) 1981 paper by Brian Kernighan (of K&R fame) entitled "Why Pascal is Not My Favorite Programming Language", which was turned down by the technical journals but circulated widely via photocopies. It was eventually published in "Comparing and Assessing Programming Languages", edited by Alan Feuer and Narain Gehani (Prentice-Hall, 1984). Part of his discussion is worth repeating here, because its criticisms are still apposite to Pascal itself after many years of improvement and could also stand as an indictment of many other bondage-and-discipline languages. (The entire essay is available at http://www.lysator.liu.se/c/bwk-on-pascal.html.) At the end of a summary of the case against Pascal, Kernighan wrote:

9. There is no escape

This last point is perhaps the most important. The language is inadequate but circumscribed, because there is no way to escape its limitations. There are no casts to disable the type-checking when necessary. There is no way to replace the defective run-time environment with a sensible one, unless one controls the compiler that defines the "standard procedures". The language is closed.

People who use Pascal for serious programming fall into a fatal trap. Because the language is impotent, it must be extended. But each group extends Pascal in its own direction, to make it look like whatever language they really want. Extensions for separate compilation, FORTRAN-like COMMON, string data types, internal static variables, initialization, octal numbers, bit operators, etc., all add to the utility of the language for one group but destroy its portability to others.

I feel that it is a mistake to use Pascal for anything much beyond its original target. In its pure form, Pascal is a toy language, suitable for teaching but not for real programming.

Pascal has since been entirely displaced (mainly by C) from the niches it had acquired in serious applications and systems programming, and from its role as a teaching language by Java.

--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.

Pascal (Pa) is also used in physics to define the pressure exerted by a force of one newton (N) on an area of one square metre.

It's the standard unit of pressure in the SI metric system.

Why "Why Pascal is Not My Favorite Programming Language" is bogus.

It's funny that the "Why Pascal..." is always brought up in such discussions. It was written way before Pascal had its finest hour with nearly total dominance in the bulk compiler world with Turbo Pascal, and its broadly praised successor Delphi.

Also it was a mere opinion of a certain person that was commit to another language. (which he even happened to design, and is the only reason why the article made history anyways. It can't be for its contents).

But the zealots of that language keep bringing it up, without ever researching it. It is simply quoted on the basis of the name of the author and the catchy title alone.

Nearly zero of the limitations named in this article apply to modern versions (which are the ones that were actually used) The real old Pascals did have their disadvantages, and though a little bit exagerated, the article has its merits with respect to those old pre 1985 versions.

It's like digging up some article from 1980 that explains how C evolved from a macro assembler, and then disallow C++, VC++ and GCC because of it.

The Pascal vs C article should be placed in the context of its time, and not randomly pulled from the grave at every occurance of the word "Pascal"

Pascal as a C keyword specifies the calling convention for a function. There are essentially two things that a calling convention determines1: whether the arguments on the stack are cleaned up by the caller or by the function and whether the arguments are passed left to right or right to left. Because there are four different combinations of these choices, programmers at one time experimented with all of them, three being common to this day.

Pascal calling convention is common, at least, because it was the calling format used for callback functions in Windows versions prior to Windows 95 and Windows NT. It is, of course, the convention used by default in Pascal programs. Arguments are passed on the stack from left to right and the called procedure pops the passed arguments off of the stack. If writing in C, failing to declare callback procedures (like your WinProc) as Pascal will cause consistently bad values to be received likely causing a swift program crash. Calling a C function from a Pascal program can have similarly bad results if yor Pascal compiler doesn't recognize what you're doing and adjust accordingly.

C (or __cdecl) calling convention is the default calling convention used in the C programming language and is used by callback functions in the Linux kernel. Arguments are passed right to left and the called procedure leaves its arguments on the stack. The advantage of passing arguments in this seemingly non-intuitive fashion is that it allows variable length argument lists using the ... notation in C, such as with printf. Leaving the passed arguments on the stack is useful if multiple functions will be called with the same arguments or if the stack happens to be a good place to store these arguments. Unfortunately, since the called procedure is free to change these values unless they are declared const, (and they normally aren't) this isn't very useful.

Recent versions of Windows including the Windows 95, 98, ME series and the Windows NT, 2K, XP series use the WinAPI (or __stdcall) calling convention for callback functions. Arguments are passed right to left and the called procedure pops the passed arguments off of the stack. If writing in C, failure to declare your callback procedures as WinAPI will likely cause a crash as soon as your callback routine returns. A toy program with such a flaw will often run fine until it terminates, at which point it will mysteriously crash.

1 Calling convention can also determine the format of the symbol generated in the object file (prefixed with an underscore, postfixed with argument specifies, etc.), exception handling, return conventions, and passing of object pointers

Log in or registerto write something here or to contact authors.