Modula-2 and Oberon
Total Page:16
File Type:pdf, Size:1020Kb
Modula-2 and Oberon Niklaus Wirth ETH Zurich [email protected] Abstract scientific circles and COBOL in business data processing. IBM’s PL/I was slowly gaining acceptance. It tried to unite the disparate This is an account of the development of the languages Modula-2 worlds of scientific and business applications. Some further, and Oberon. Together with their ancestors ALGOL 60 and Pascal "esoteric" languages were popular in academia, for example Lisp they form a family called Algol-like languages. Pascal (1970) and its extensions, which dominated the AI culture with its list- reflected the ideas of structured programming, Modula-2 (1979) processing facilities. added those of modular system design, and Oberon (1988) catered However, none of the available languages was truly suitable to the object-oriented style. Thus they mirror the essential for handling the ever-growing complexity of computing tasks. programming paradigms of the past decades. Here the major FORTRAN and COBOL lacked a pervasive concept of data types language properties are outlined, followed by an account of the like that of Pascal; and Pascal lacked a facility for piecewise respective implementation efforts. The conditions and the compilation, and thus for program libraries. PL/1 offered environments in which the languages were created are elucidated. everything to a certain degree. Therefore it was bulky and hard to We point out that simplicity of design was the most essential master. The fact remained that none of the available languages guiding principle. Clarity of concepts, economy of features, was truly satisfactory. efficiency and reliability of implementations were its I was fortunate to be able to spend a sabbatical year at the new consequences. Xerox Research Laboratory in Palo Alto during this time. There, Categories and Subject Descriptors D.3.3 [Programming on the personal workstation Alto, I encountered the language Languages]: Language Constructs and Features – abstract data Mesa, which appeared to be the appropriate language for types, classes and objects, modules. programming large systems. It stemmed from Pascal [2, 38], and hence had adopted a strictly static typing scheme. But one was General Terms Design, Reliability, Languages. also allowed to develop parts of a system – called modules – independently, and to bind them through the linking loader into a 1. Background consistent whole. This alone was nothing new. It was new, however, for strongly typed languages, guaranteeing type In the middle of the 1970s, the computing scene evolved around consistency between the linked modules. Therefore, compilation large computers. Programmers predominantly used time-shared of modules was not called independent, but separate compilation. "main frames" remotely via low-bandwidth (1200 b/s) lines and We will return to this topic later. simple ("dumb") terminals displaying 24 lines of up to 80 As Pascal had been Mesa’s ancestor, Mesa served as Modula- characters. Accordingly, interactivity was severely limited, and 2’s guideline. Mesa had not only adopted Pascal’s style and program development and testing was a time-consuming process. concepts, but also most of its facilities, to which were added Yet, the power of computers – albeit tiny in comparison with many more, as they all seemed either necessary or convenient for modern devices – had grown considerably over the previous system programming. The result was a large language, difficult to decade. Therefore the complexity of tasks, and thus that of fully master, and more so to implement. Making a virtue out of programs, had grown likewise. The notion of parallel processes necessity, I simplified Mesa, retaining what seemed essential and had become a concern and made programming even more preserving the appearance of Pascal. The guiding idea was to difficult. The limit of our intellectual capability seemed to be construct a genuine successor of Pascal meeting the requirements reached, and a noteworthy conference in 1968 gave birth to the of system engineering, yet also to satisfy my teacher’s urge to term software crisis [1, p.120]. present a systematic, consistent, appealing, and teachable Small wonder, then, that hopes rested on the advent of better framework for professional programming. tools. They were seen in new programming languages, symbolic In later years, I was often asked whether indeed I had designed debuggers, and team management. Dijkstra put the emphasis on Pascal and Modula-2 as languages for teaching. The answer is better education. Already in the mid-1960s he had outlined his "Yes, but not only". I wanted to teach programming rather than a discipline of structured programming [3], and the language Pascal language. A language, however, is needed to express programs. followed his ideas and represented an incarnation of a structured Thus, the language must be an appropriate tool, both for language [2]. But the dominating languages were FORTRAN in formulating programs and for expressing the basic concepts. It Permission to make digital/hard copy of part of this work for personal or must be supportive, rather than a burden! But I also hasten to add classroomPermission touse make is granteddigital or without hard copies fee of provided all or part that of this the work copies for personalare not or that Pascal and Modula-2 were not intended to remain confined to madeclassroom or distributeduse is granted for without profit fee or provide commerciald that copies advantage, are not made the orcopyright distributed the academic classroom. They were expected to be useful in notice,for profit the or title commercial of the publication,advantage and a ndthat its copies date ofbear appear, this notice and andnotice the isfull practice. Further comments can be found in [44]. givencitation thaton the copying first page. is Toby copy permission otherwise, orof republish,the ACM, to post Inc. on Toservers copy or to To be accurate, I had designed and implemented the otherwise,redistribute toto lists, republish, requires priorto post specific on servers,permission or and/or to redistribute a fee. to lists, SIGPLAN’05 June 12–15, 2005, Location, State, Country. predecessor language Modula [7 - 9] in 1975. It had been requiresCopyright prior© 2004 specific ACM 1-59593- permissionXXX-X/0X/000X…$5.00. and/or a fee. Permission may be requested from the Publications Dept., ACM, Inc., 2 Penn Plaza, New York, NY 11201-0701, USA, fax:+1(212) 869-0481, [email protected] ©2007 ACM 978-1-59593-766-7/2007/06-ART3 $5.00 3-1 DOI 10.1145/1238844.1238847 http://doi.acm.org/10.1145/1238844.1238847 conceived not as a general-purpose language, but rather as a unless it occurs in the module’s import list. This definition makes small, custom-tailored language for experimenting with sense if modules are considered as nestable, and it represents the concurrent processes and primitives for their synchronization. Its concept of information hiding as first postulated by Parnas in features were essentially confined to this topic, such as process, 1972 [4]. signal, and monitor [6]. The monitor, representing critical regions Visibility being controlled by modules and existence by with mutual exclusion, mutated into modules in Modula-2. procedures, the example of the pseudo-random number generator Modula-2 was planned to be a full-scale language for now turns out as follows in Modula-2. Local variables of modules implementing the entire software for the planned personal are allocated when the module is loaded, and remain allocated workstation Lilith [12, 19]. This had to include device drivers and until the module is explicitly discarded: storage allocator, as well as applications like document preparation and e-mail systems. module RandomNumbers; As it turned out later, Modula-2 was rather too complex. The export random; result of an effort at simplification ten years later was Oberon. var x: real; procedure random(): real; 2. The Language Modula-2 begin x := (c1*x +c2) mod c3; return x The defining report of Modula-2 appeared in 1979, and a textbook end random; on it in 1982 [13]. A tutorial was published, following the begin x := c0 (*seed*) growing popularity of the language [17, 18]. In planning Modula- end RandomNumbers 2, I saw it as a new version of Pascal updated to the requirements of the time, and I seized the opportunity to correct various The notation for a module was chosen identical to that of a mistakes in Pascal’s design, such as, for example, the syntactic monitor proposed by Hoare in 1974 [6], but lacks connotation of anomaly of the dangling "else", the incomplete specification of mutual exclusion of concurrent processes (as it was in Modula-1 procedure parameters, and others. Apart from relatively minor [7]). corrections and additions, the primary innovation was that of Modula-2’s module can also be regarded as a representation of modules. the concept of abstract data type postulated by Liskov in 1974 [5]. A module representing an abstract type exports the type, 2.1 Modules typically a record structured type, and the set of procedures and functions applicable to it. The type’s structure remains invisible ALGOL had introduced the important notions of limited scopes of and inaccessible from the outside of the module. Such a type is identifiers and of the temporary existence of objects. The limited called opaque. This makes it possible to postulate module visibility of an identifier and the limited lifetime of an object invariants. Probably the most popular example is the stack. (For (variable, procedure), however, were tightly coupled: All existing simplicity, we refrain from providing the guards s.n < N for push objects were visible, and the ones that were not visible did not and s.n > 0 for pop). exist (were not allocated). This tight coupling was an obstacle in some situations. We refer to the well-known function to generate module Stacks; the next pseudo-random number, where the last one must be export Stack, push, pop, init; stored to compute the next, while remaining invisible.