Object-Oriented Programming in the Beta Programming Language
Total Page:16
File Type:pdf, Size:1020Kb
OBJECT-ORIENTED PROGRAMMING IN THE BETA PROGRAMMING LANGUAGE OLE LEHRMANN MADSEN Aarhus University BIRGER MØLLER-PEDERSEN Ericsson Research, Applied Research Center, Oslo KRISTEN NYGAARD University of Oslo Copyright c 1993 by Ole Lehrmann Madsen, Birger Møller-Pedersen, and Kristen Nygaard. All rights reserved. No part of this book may be copied or distributed without the prior written permission of the authors Preface This is a book on object-oriented programming and the BETA programming language. Object-oriented programming originated with the Simula languages developed at the Norwegian Computing Center, Oslo, in the 1960s. The first Simula language, Simula I, was intended for writing simulation programs. Si- mula I was later used as a basis for defining a general purpose programming language, Simula 67. In addition to being a programming language, Simula1 was also designed as a language for describing and communicating about sys- tems in general. Simula has been used by a relatively small community for many years, although it has had a major impact on research in computer sci- ence. The real breakthrough for object-oriented programming came with the development of Smalltalk. Since then, a large number of programming lan- guages based on Simula concepts have appeared. C++ is the language that has had the greatest influence on the use of object-oriented programming in industry. Object-oriented programming has also been the subject of intensive research, resulting in a large number of important contributions. The authors of this book, together with Bent Bruun Kristensen, have been involved in the BETA project since 1975, the aim of which is to develop con- cepts, constructs and tools for programming. The BETA language is one main result of this project, the various stages of which have been described in many different reports and articles (Kristensen et al., 1976; 1983a,b; 1985; 1987a,b; 1988; Madsen, 1987; Madsen and Møller-Pedersen, 1988; 1989a,b; 1992; Madsen et al., 1983). This book contains a description of the BETA language together with the conceptual framework on which BETA has been based. The Mjølner2 BETA System is a programming environment supporting object-oriented programming in BETA. The Mjølner BETA System has been developed by the Mjølner project (Dahle et al., 1986; Knudsen et al., 1992), which was a cooperative Nordic project with participants from Sweden, Nor- way, Finland and Denmark. The Mjølner BETA System includes an imple- mentation of BETA and a large number of libraries and application frame- works. It also includes a Hyper Structure Editor and an object-oriented CASE 1Simula 67 was later renamed to just Simula, which is used in this book. 2The name Mjølner is taken from Nordic mythology, where Mjølner is the name of the god Thor’s hammer. According to mythology, this hammer is the perfect tool that cannot fail, grows with the task, and always comes back to Thor’s hand. v vi PREFACE tool for supporting design using BETA. The system is a commercial product marketed by Mjølner Informatics A/S. Appendix B contains a more detailed description of the Mjølner BETA System. Readers should consult the Mjølner manuals for further details before trying to run the examples in this book. The Mjølner BETA System is currently available for the Macintosh, and for a number of UNIX-based workstations runnning X-Window Systems. Draft versions of this book and pre-releases of the Mjølner BETA System have been used for teaching object-oriented programming at the Department of Information and Media Sciences (IMV) and the Computer Science Depart- ment (DAIMI), both at Aarhus University. At IMV, BETA is used for introduc- tory programming and at DAIMI it is used as a second year course in program- ming languages. They have also been used for teaching at a number of other places, including the Universities of Copenhagen, Oslo, Bergen and Odense. Draft versions have also been used for BETA tutorials given at the OOPSLA ’89, ’90 and ’91 conferences (Object-Oriented Programming, Languages, Sys- tem and Applications), at the TOOLS ’91 and ’92 conferences (Technology of Object-Oriented Languages and Systems), and at EastEurOOPe ’91 (East Eu- ropean Conference on Object-Oriented Programming). The book is organized as follows: Chapters 1 and 2 introduce the basic concepts of object-oriented programming; Chapters 3–12 are a description of subjects such as objects, patterns, sequential execution, the virtual concept, block structure and procedural programming. The multi-sequential aspects of BETA, including coroutines and concurrency, are described in Chapters 13–15. Chapter 16 deals with exception handling, Chapter 17 describes the modularization of large programs, and Chapter 18 presents the conceptual framework underlying BETA. Appendix A includes a grammar for BETA, and Appendix B gives a description of the Mjølner BETA System. When reading the book, there are three main subject areas that should be covered at the same time: ¡ The BETA language, Chapters 3–16 ¡ Modularization, Chapter 17 ¡ The conceptual framework, Chapters 2 and 18. It is recommended that readers start with Chapters 1–6; Chapter 2 introduces part of the conceptual framework, and Chapters 3–6 introduce part of BETA. Chapter 18, the main chapter on the conceptual framework, may then be read before reading Chapters 7–16. Depending on the reader’s previous ex- perience, it may be difficult to grasp Chapter 18 on a first reading, so it is recommended that this is read again after having read the book’s remaining chapters. In a teaching situation it is recommended that the concepts detailed in Chapter 18 are discussed while reading the remaining chapters of the book. PREFACE vii Chapter 17, on modularization, may be read after Chapters 3–6. In a teach- ing situation it is recommended that it is read as soon as the students have to write other than just trivial programs. Experience shows that, from the begin- ning, students should be trained in splitting a program into convenient mod- ules, including the separation of interface and implementation. Acknowledgements The BETA project was initiated in 1976 as part of what was then called The Joint Language Project. People from The Regional Computing Center and Computer Science Department at Aarhus University, the Institute for Elec- tronic Systems at Aalborg University Centre, and the Norwegian Computing Center, Oslo participated in that project. The initiative for the project was taken in the autumn of 1975 by Bjarner Svejgaard, Director of The Regional Computing Center. The BETA language was developed by the authors together with Bent Bruun Kristensen. In addition, a large number of people have been involved in the development of BETA and the Mjølner BETA System, including col- leagues and students at Aarhus University, The Norwegian Computing Center, Oslo University, Aalborg University, and Mjølner Informatics. In particular, the contributions of Dag Belsnes and Jørgen Lindskov Knudsen are acknowl- edged. Development of the Mjølner BETA System in the Nordic Mjølner project has been supported by The Nordic Fund for Technology and Research. Partic- ipants in the Mjølner Project come from Lund University, Telesoft, EB Tech- nology, The Norwegian Computing Center, Telenokia, Sysware ApS, Aalborg University and Aarhus University. The main implementors of the Mjølner BETA System are Peter Andersen, Lars Bak, Jørgen Lindskov Knudsen, Ole Lehrmann Madsen, Kim Jensen Møller, Claus Nørgaard, and Elmer Sandvad. In addition, Karen Borup, Søren Brandt, Jørgen Nørgaard, Claus H. Peder- sen, Tommy Thorn, Per Fack Sørensen and Peter Ørbæk have participated in various parts of the implementation. The development of the Mjølner BETA System has been supported through a contract with Apple Computer Europe, Paris. We are grateful to Larry Taylor for the great support he has provided for BETA. Development of the system has also been supported by a contract with Apollo Computer, Finland, and by the donation of workstations from Hewlett-Packard. The development of BETA and the Mjølner BETA System has been sup- ported by the Danish Natural Science Research Council, grant. no. 11-3106, FTU 5.17.5.1.25, the Danish Natural Research Council, grant. no. 11-8285, the Danish Research Programme for Informatics, grant nos. 5.26.18.29. (the Devise Project), The Royal Norwegian Council for Scientific and Industrial Research, grant no. ED 0223.16641 (the Scala project), and through the Euro- viii PREFACE pean Commission’s Esprit EuroCoOp (5303) and EuroCODE (6155) projects. We would like to thank colleagues and students for valuable comments, inspiring criticisms, and the discovery of errors in preliminary versions of this book. Kim Halskov Madsen and Randell Trigg deserve special thanks for their use of preliminary versions of the book in teaching at IMV; their experience and comments have had a large influence. Other useful comments have been provided by Birger Andersen, Peter Andersen, Lars Bak, Lone Faber, Carsten Hansen, Dag Helstad, Anette Hviid, Jørgen Lindskov Knudsen, Kim Jensen Møller, Elmer Sandvad, Alexandre Valente Sousa, Kristine Stougaard Thom- sen, and the many students who have been exposed to previous versions of the book. We would like to thank Peter Wegner for his useful comments and encour- agement to write this book and Simon Plumtree of Addison-Wesley for his pa- tience. During the preparation of the manuscript we received great help from Susanne Brøndberg, Karen Kjær Møller and the production staff at Addison- Wesley. The authors would like to thank their families (Ole: Marianne, Christian, Anne Sofie; Birger: Kirsten, Kamilla, Kristine; Kristen: Johanna and to a moderate extent children and grandchildren). The BETA project would not have been the same and this book would not have come into existence without their patience and understanding, and without their participation in many lively gatherings3 throughout the years. Ole Lehrmann Madsen Birger Møller-Pedersen Kristen Nygaard May 1993 3We also thank the white wine producers in Germany, France, Italy and California.