Programming Language Design, Essays (university) of System Programming

Guide to programming Languages

Typology: Essays (university)

2017/2018

Uploaded on 02/09/2018

edgar-kibet
edgar-kibet 🇰🇪

1 document

1 / 492

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Programming Language Design and more Essays (university) System Programming in PDF only on Docsity!

PROGRAMMING LANGUAGE

DESIGN CONCEPTS

PROGRAMMING LANGUAGE

DESIGN CONCEPTS

David A. Watt, University of Glasgow

with contributions by

William Findlay, University of Glasgow

Copyright  2004 John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England Telephone (+44) 1243 779777

Email (for orders and customer service enquiries): [email protected] Visit our Home Page on www.wileyeurope.com or www.wiley.com

All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP, UK, without the permission in writing of the Publisher, with the exception of any material supplied specifically for the purpose of being entered and executed on a computer system for exclusive use by the purchase of the publication. Requests to the Publisher should be addressed to the Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England, or emailed to [email protected], or faxed to (+44) 1243 770620.

This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the Publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought.

ADA is a registered trademark of the US Government Ada Joint Program Office.

JAVA is a registered trademark of Sun Microsystems Inc.

OCCAM is a registered trademark of the INMOS Group of Companies.

UNIX is a registered trademark of AT&T Bell Laboratories.

Other Wiley Editorial Offices

John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA

Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA

Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany

John Wiley & Sons Australia Ltd, 33 Park Road, Milton, Queensland 4064, Australia

John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809

John Wiley & Sons Canada Ltd, 22 Worcester Road, Etobicoke, Ontario, Canada M9W 1L

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Cataloging-in-Publication Data

Watt, David A. (David Anthony) Programming language design concepts / David A. Watt ; with contributions by William Findlay. p. cm. Includes bibliographical references and index. ISBN 0-470-85320-4 (pbk. : alk. paper)

  1. Programming languages (Electronic computers) I. Findlay, William, 1947- II. Title. QA76.7 .W388 2004 005.13 – dc 2003026236

British Library Cataloguing in Publication Data

A catalogue record for this book is available from the British Library

ISBN 0-470-85320-

Typeset in 10/12pt TimesTen by Laserwords Private Limited, Chennai, India Printed and bound in Great Britain by Biddles Ltd, King’s Lynn This book is printed on acid-free paper responsibly manufactured from sustainable forestry in which at least two trees are planted for each one used for paper production.

Contents

Preface

The first programming language I ever learned was A LGOL60. This language was notable for its elegance and its regularity; for all its imperfections, it stood head and shoulders above its contemporaries. My interest in languages was awakened, and I began to perceive the benefits of simplicity and consistency in language design. Since then I have learned and programmed in about a dozen other languages, and I have struck a nodding acquaintance with many more. Like many pro- grammers, I have found that certain languages make programming distasteful, a drudgery; others make programming enjoyable, even esthetically pleasing. A good language, like a good mathematical notation, helps us to formulate and communi- cate ideas clearly. My personal favorites have been PASCAL, A DA , ML, and J AVA. Each of these languages has sharpened my understanding of what programming is (or should be) all about. P ASCAL taught me structured programming and data types. A DA taught me data abstraction, exception handling, and large-scale pro- gramming. ML taught me functional programming and parametric polymorphism. J AVA taught me object-oriented programming and inclusion polymorphism. I had previously met all of these concepts, and understood them in principle, but I did not truly understand them until I had the opportunity to program in languages that exposed them clearly.

Contents

This book consists of five parts. Chapter 1 introduces the book with an overview of programming linguistics (the study of programming languages) and a brief history of programming and scripting languages. Chapters 2–5 explain the basic concepts that underlie almost all programming languages: values and types, variables and storage, bindings and scope, procedures and parameters. The emphasis in these chapters is on identifying the basic concepts and studying them individually. These basic concepts are found in almost all languages. Chapters 6–10 continue this theme by examining some more advanced con- cepts: data abstraction (packages, abstract types, and classes), generic abstraction (or templates), type systems (inclusion polymorphism, parametric polymor- phism, overloading, and type conversions), sequencers (including exceptions), and concurrency (primitives, conditional critical regions, monitors, and rendezvous). These more advanced concepts are found in the more modern languages. Chapters 11–16 survey the most important programming paradigms, compar- ing and contrasting the long-established paradigm of imperative programming with the increasingly important paradigms of object-oriented and concurrent pro- gramming, the more specialized paradigms of functional and logic programming, and the paradigm of scripting. These different paradigms are based on different

xv

xvi Preface

selections of key concepts, and give rise to sharply contrasting styles of language and of programming. Each chapter identifies the key concepts of the subject paradigm, and presents an overview of one or more major languages, showing how concepts were selected and combined when the language was designed. Several designs and implementations of a simple spellchecker are presented to illustrate the pragmatics of programming in all of the major languages. Chapters 17 and 18 conclude the book by looking at two issues: how to select a suitable language for a software development project, and how to design a new language. The book need not be read sequentially. Chapters 1–5 should certainly be read first, but the remaining chapters could be read in many different orders. Chapters 11–15 are largely self-contained; my recommendation is to read at least some of them after Chapters 1–5, in order to gain some insight into how major languages have been designed. Figure P.1 summarizes the dependencies between the chapters.

Examples and case studies

The concepts studied in Chapters 2–10 are freely illustrated by examples. These examples are drawn primarily from C, C++, JAVA , and A DA. I have chosen these languages because they are well known, they contrast well, and even their flaws are instructive!

1 Introduction

2 Values and Types

4 Bindings and Scope

5 Procedural Abstraction

6 Data Abstraction

7 Generic Abstraction

11 Imperative Programming

12 OO Programming

15 Logic Programming

17 Language Selection

18 Language Design

3 Variables and Storage

8 Type Systems

14 Functional Programming

9 Control Flow

13 Concurrent Programming

16 Scripting

10 Concurrency

Figure P.1 Dependencies between chapters of this book.

xviii Preface

student will need to follow up with more advanced studies. The book has an extensive bibliography, and each chapter closes with suggestions for further reading on the topics covered by the chapter.

Acknowledgments

Bob Tennent’s classic book Programming Language Principles has profoundly influenced the way I have organized this book. Many books on programming languages have tended to be syntax-oriented , examining several popular languages feature by feature, without offering much insight into the underlying concepts or how future languages might be designed. Some books are implementation- oriented , attempting to explain concepts by showing how they are implemented on computers. By contrast, Tennent’s book is semantics-oriented , first identifying and explaining powerful and general semantic concepts, and only then analyzing particular languages in terms of these concepts. In this book I have adopted Ten- nent’s semantics-oriented approach, but placing far more emphasis on concepts that have become more prominent in the intervening two decades. I have also been strongly influenced, in many different ways, by the work of Malcolm Atkinson, Peter Buneman, Luca Cardelli, Frank DeRemer, Edsger Dijkstra, Tony Hoare, Jean Ichbiah, John Hughes, Mehdi Jazayeri, Bill Joy, Robin Milner, Peter Mosses, Simon Peyton Jones, Phil Wadler, and Niklaus Wirth. I wish to thank Bill Findlay for the two chapters (Chapters 10 and 13) he has contributed to this book. His expertise on concurrent programming has made this book broader in scope than I could have made it myself. His numerous suggestions for my own chapters have been challenging and insightful. Last but not least, I would like to thank the Wiley reviewers for their constructive criticisms, and to acknowledge the assistance of the Wiley editorial staff led by Gaynor Redvers-Mutton.

David A. Watt Brisbane March 2004

PART I

INTRODUCTION

Part I introduces the book with an overview of programming linguistics and a brief history of programming and scripting languages.