AT&T Bell Laboratories Murray Hill, New Jersey 07974Computing Science Technical Report No. 100Why Pascal is Not My Favorite Programming LanguageBrian W. KernighanApril 2, 1981Why Pascal is Not My Favorite Programming LanguageBrian W. KernighanAT&T Bell Laboratories Murray Hill, New Jersey 07974ABSTRACTThe programming language Pascal has become the dominant language ofinstruction in computer science education. It has also strongly influencedlan guages developed subsequently, in particular Ada.Pascal was originally intended primarily as a teaching language, but it hasbeen more and more often recommended as a language for serious programming aswell, for example, for system programming tasks and even operating systems.Pascal, at least in its standard form, is just plain not suitable for seriouspro gramming. This paper discusses my personal discovery of some of thereasons why.April 2, 1981Why Pascal is Not My Favorite Programming LanguageBrian W. KernighanAT&T Bell Laboratories Murray Hill, New Jersey 079741. GenesisThis paper has its origins in two events -- a spate of papers that compare Cand Pas cal 1, 2, 3, 4 and a personal attempt to rewrite Software Tools 5 inPascal.Comparing C and Pascal is rather like comparing a Learjet to a Piper Cub --one is meant for getting something done while the other is meant for learning-- so such comparisons tend to be somewhat farfetched. But the revision ofSoftware Tools seems a more relevant comparison. The programs therein wereoriginally written in Ratfor, a ``structured'' dialect of Fortran imple mentedby a preprocessor. Since Ratfor is really Fortran in disguise, it has few ofthe assets that Pascal brings -- data types more suited to characterprocessing, data structuring capabilities for better defining the organizationof one's data, and strong typing to enforce telling the truth about the data.It turned out to be harder than I had expected to rewrite the programs inPascal. This paper is an attempt to distill out of the experience somelessons about Pascal's suitability for program ming (as distinguished fromlearning about programming). It is not a comparison of Pascal with C orRatfor.The programs were first written in that dialect of Pascal supported by thePascal interpreter pi provided by the University of California at Berkeley.The language is close to the nominal standard of Jensen and Wirth, 6 with gooddiagnostics and careful run-time checking. Since then, the programs have alsobeen run, unchanged except for new libraries of primitives, on four othersystems: an interpreter from the Free University of Amsterdam (hereinafterreferred to as VU, for Vrije Universiteit), a VAX version of the Berkeleysystem (a true compiler), a compiler purveyed by Whitesmiths, Ltd., and UCSDPascal on a Z80. All but the last of these Pascal systems are written in C.Pascal is a much-discussed language. A recent bibliography 7 lists 175 itemsunder the heading of ``discussion, analysis and debate.'' The most oftencited papers (well worth reading) are a strong critique by Habermann 8 and anequally strong rejoinder by Lecarme and Des jardins. 9 The paper by Boom andDeJong 10 is also good reading. Wirth's own assessment of Pas cal is found in[11]. I have no desire or ability to summarize the literature; this paperrepresents my personal observations and most of it necessarily duplicatespoints made by others. I have tried to organize the rest of the materialaround the issues oftypes and scope[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>