Why Pascal Is Not My Favorite Programming Language ( 1981 )

ksec1 pts0 comments

Why Pascal is Not My Favorite Programming Language

Why Pascal is Not My Favorite Programming Language

Brian W. Kernighan,<br>April 2, 1981

AT&T Bell Laboratories,  Murray Hill, New Jersey 07974

Abstract

The programming language Pascal has become the dominant language<br>of instruction in computer science education.  It has also strongly<br>influenced languages developed subsequently, in particular Ada.

Pascal was originally intended primarily as a teaching language,<br>but it has been more and more often recommended as a language for<br>serious programming as well, for example, for system programming<br>tasks and even operating systems.

Pascal, at least in its standard form, is just plain not<br>suitable for serious programming.  This paper discusses my personal<br>discovery of some of the reasons why.

1.  Genesis

This paper has its origins in two events - a spate of papers that compare<br>C and Pascal(1, 2,<br>3, 4) and a personal<br>attempt to rewrite 'Software Tools'(5) in Pascal.

Comparing C and Pascal is rather like comparing a Learjet to a Piper Cub<br>- one is meant for getting something done while the other is meant for<br>learning - so such comparisons tend to be somewhat farfetched.  But the<br>revision of Software Tools seems a more relevant comparison.  The programs<br>therein were originally written in Ratfor, a ``structured'' dialect of<br>Fortran implemented by a preprocessor.  Since Ratfor is really Fortran in<br>disguise, it has few of the assets that Pascal brings - data types more<br>suited to character processing, data structuring capabilities for better<br>defining the organization of one's data, and strong typing to enforce<br>telling the truth about the data.

It turned out to be harder than I had expected to rewrite the programs in<br>Pascal.  This paper is an attempt to distill out of the experience some<br>lessons about Pascal's suitability for programming (as distinguished from<br>learning about programming).  It is not a comparison of Pascal with C or<br>Ratfor.

The programs were first written in that dialect of Pascal supported by<br>the Pascal interpreter pi provided by the University of California at<br>Berkeley.  The language is close to the nominal standard of Jensen and<br>Wirth,(6) with good diagnostics and careful run-time checking.  Since then,<br>the programs have also been run, unchanged except for new libraries of<br>primitives, on four other systems: an interpreter from the Free University<br>of Amsterdam (hereinafter referred to as VU, for Vrije Universiteit), a VAX<br>version of the Berkeley system (a true compiler), a compiler purveyed by<br>Whitesmiths, Ltd., and UCSD Pascal on a Z80.  All but the last of these<br>Pascal systems are written in C.

Pascal is a much-discussed language.  A recent bibliography(7) lists 175<br>items under the heading of ``discussion, analysis and debate.'' The most<br>often cited papers (well worth reading) are a strong critique by<br>Habermann(8) and an equally strong rejoinder by Lecarme and Desjardins.(9)<br>The paper by Boom and DeJong(10) is also good reading.  Wirth's own<br>assessment of Pascal is found in [11].  I have no desire or ability to<br>summarize the literature; this paper represents my personal observations<br>and most of it necessarily duplicates points made by others.  I have tried<br>to organize the rest of the material around the issues of

types and scope<br>control flow<br>environment<br>cosmetics

and within each area more or less in decreasing order of significance.

To state my conclusions at the outset: Pascal may be an admirable<br>language for teaching beginners how to program; I have no first-hand<br>experience with that.  It was a considerable achievement for 1968.  It has<br>certainly influenced the design of recent languages, of which Ada is likely<br>to be the most important.  But in its standard form (both current and<br>proposed), Pascal is not adequate for writing real programs.  It is suitable<br>only for small, self-contained programs that have only trivial interactions<br>with their environment and that make no use of any software written by<br>anyone else.

2.  Types and Scopes

Pascal is (almost) a strongly typed language.  Roughly speaking, that<br>means that each object in a program has a well-defined type which<br>implicitly defines the legal values of and operations on the object.  The<br>language guarantees that it will prohibit illegal values and operations, by<br>some mixture of compile- and run-time checking.  Of course compilers may not<br>actually do all the checking implied in the language definition.<br>Furthermore, strong typing is not to be confused with dimensional analysis.<br>If one defines types 'apple' and 'orange' with

type<br>apple = integer;<br>orange = integer;

then any arbitrary arithmetic expression involving apples and oranges is<br>perfectly legal.<br>Strong typing shows up in a variety of ways.  For instance, arguments to<br>functions and procedures are checked for proper type matching.  Gone is the<br>Fortran freedom to pass a floating point number into a subroutine that<br>expects an integer; this I deem a desirable attribute of Pascal, since...

pascal language programming programs paper strong

Related Articles