Chapter 3 Louden1 Chapter 3 - Language Design Principles Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.

Slides:



Advertisements
Similar presentations
1 Chapter 3 - Language Design Principles. Thought question What characteristics should be present in your “perfect language”? What have you liked/disliked.
Advertisements

Programming Languages and Paradigms
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Names and Bindings.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Why is Java so popular? Floundered until adapted for internet. 90% of personal computers have Java Run on client – so load to server is drastically reduced.
Programming Languages Language Design Issues Why study programming languages Language development Software architectures Design goals Attributes of a good.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
Louden, Chapter 3 - Language Design Principles Programming Languages: Principles and Practice, 2nd Ed.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
Reasons to study concepts of PL
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
Programming Languages Structure
Context-sensitive Analysis, II Ad-hoc syntax-directed translation, Symbol Tables, andTypes.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Guide To UNIX Using Linux Third Edition
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
1 Programming Languages Marjan Sirjani 2 1- The Study of Programming Languages The purpose of language is simply that it must convey meaning. (Confucius)
Language Evaluation Criteria
PROGRAMMING LANGUAGES The Study of Programming Languages.
Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
Programming Languages Third Edition Chapter 2 Language Design Criteria.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS 363 Comparative Programming Languages
Gary MarsdenSlide 1University of Cape Town Principles of programming language design Gary Marsden Semester 2 – 2001.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
Chapter 1 - Introduction
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
1 Programming Languages Marjan Sirjani Course web site:
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
ProgrammingLanguages Programming Languages The Extended Design Principles This lecture introduces a list of more specific principles that can be an aid.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
Chapter 3 - Language Design Principles
Engr. Isabelo Jun D. Paat, ME-CoE Lecturer 1 Programming Languages.
Object-Oriented Programming Chapter Chapter
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
Programming Language Design Issues Programming Languages – Principles and Practice by Kenneth C Louden.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
Names, Bindings, Type Checking and Scopes. Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Programming Languages 2nd edition Tucker and Noonan
CSE3302 Programming Languages (notes continued)
Basic Concepts: computer, program, programming …
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
PROGRAMMING LANGUAGES
Programming Languages 2nd edition Tucker and Noonan
Principles of Programming Languages
Names and Binding In Text: Chapter 5.
Chapter 1 Preliminaries.
Presentation transcript:

Chapter 3 Louden1 Chapter 3 - Language Design Principles Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden

Chapter 3 Louden2 The language design problem Language design is difficult, and success is hard to predict: –Pascal a success, Modula-2 a failure –Algol60 a success, Algol68 a failure –FORTRAN a success, PL/I a failure Conflicting advice

Chapter 3 Louden3 Efficiency The “first” goal (FORTRAN): execution efficiency. Still an important goal in some settings (C++, C). Many other criteria can be interpreted from the point of view of efficiency: –programming efficiency: writability or expressiveness (ability to express complex processes and structures) –reliability (security). –maintenance efficiency: readability. (saw this as a goal for first time in Cobol)

Chapter 3 Louden4 Other kinds of efficiency efficiency of execution (optimizable) efficiency of translation. Are there features which are extremely difficult to check at compile time (or even run time)? e.g. Alogol – prohibits assignment to dangling pointers Implementability (cost of writing translator)

Chapter 3 Louden5 Features that aid efficiency of execution Static data types allow efficient allocation and access. Manual memory management avoids overhead of “garbage collection”. Simple semantics allow for simple structure of running programs (simple environments - Chapter 8).

Chapter 3 Louden6 Note conflicts with efficiency Writability, expressiveness: no static data types (variables can hold anything, no need for type declarations). [harder to maintain] Reliability, writability, readability: automatic memory management (no need for pointers). [runs slower] Expressiveness, writability, readability: more complex semantics, allowing greater abstraction. [harder to translate]

Chapter 3 Louden7 Internal consistency of a language design: Regularity Regularity is a measure of how well a language integrates its features, so that there are no unusual restrictions, interactions, or behavior. Easy to remember. Regularity issues can often be placed in subcategories: –Generality: are constructs general enough? (Or too general?) –Orthogonality: are there strange interactions? –Uniformity: Do similar things look the same, and do different things look different?

Chapter 3 Louden8 Generality deficiencies In pascal, procedures can be passed as parameters, but no procedure variable. Pascal has no variable length arrays –length is defined as part of definition (even when parameter)

Chapter 3 Louden9 Orthogonality: independence Not context sensitive Seems similar to “generality” but more of an “odd” decision rather than a limitation. For example, if I buy a sweater, I may have the following choices: –short sleeve, long sleeve, or sleeveless –small, medium, or large –red, green, or blue

Chapter 3 Louden10 Limitations to sweater example: If it is not possible to get sleeveless sweaters, that may be a lack of generality. If any combination of any attributes can be used together, it is orthogonal. If red sweaters cannot be purchased in a small size, but other sweaters can, it is non-orthogonal

Chapter 3 Louden11 Orthogonality a relatively small set of primitive constructs can be combined in a relatively small number of ways. Every possible combination is legal. For example - in IBM assembly language there are different instructions for adding memory to register or register to register (non-orthogonal). In Vax, a single add instruction can have arbitrary operands. Closely related to simplicity - the more orthogonal, the fewer rules to remember.

Chapter 3 Louden12 For examples of non-orthogonality consider C++: –We can convert from integer to float by simply assigning a float to an integer, but not vice versa. (not a question of ability to do – generality, but of the way it is done) –Arrays are pass by reference while integers are pass by value. –A switch statement works with integers, characters, or enumerated types, but not doubles or Strings.

Chapter 3 Louden13 Regularity examples from C++ Functions are not general: there are no local functions (simplicity of environment). Declarations are not uniform: data declarations must be followed by a semicolon, function declarations must not. Lots of ways to increment – lack of uniformity (++i, i++, i = i+1) i=j and i==j look the same, but are different. Lack of uniformity

Chapter 3 Louden14 What about Java? Are function declarations non-general? –There are no functions, so a non-issue. (Well, what about static methods?) Are class declarations non-general? –No multiple inheritance (but there is a reason: complexity of environment). –Java has a good replacement: interface inheritance. Do declarations require semicolons? –Local variables do, but is that an issue? (Not really - they look like statements.)

Chapter 3 Louden15 Java regularity, continued Are some parameters references, others not? –Yes: objects are references, simple data are copies. –This is a result of the non-uniformity of data in Java, in which not every piece of data is an object. –The reason is efficiency: simple data have fast access. What is the worst non-regularity in Java? –My vote: arrays. But there are excuses.

Chapter 3 Louden16 Other design principles Simplicity: make things as simple as possible, but not simpler (Einstein). (Pascal, C) We can make things so simple that it doesn’t work well – no string handling, no reasonable I/0 Can be cumbersome to use or inefficient.

Chapter 3 Louden17 Other design principles Expressiveness: make it possible to express conceptual abstractions directly and simply. (Scheme) Helps you to think about the problem. Perl, for example, allows you to return multiple arguments: ($a,$b) = swap($a,$b);

Chapter 3 Louden18 Other design principles Extensibility: allow the programmer to extend the language in various ways. (Scheme, C++) Types, operators Security: programs cannot do unexpected damage. (Java) –discourages errors –allows errors to be discovered –type checking

Chapter 3 Louden19 Other design principles (cont.) Preciseness: having a definition that can answer programmers and implementors questions. (Most languages today, but only one has a mathematical definition: ML). If it isn’t clear, there will be differences. Example: Declaration in local scope (for loop) unknown/known after exit Example: implementation of switch statement Example: constants – expressions or not? Example: how much accuracy of float?

Chapter 3 Louden20 Other design principles (cont.) Machine-independence: should run the same on any machine. (Java- big effort) Consistent with accepted notations – easy to learn and understand for experienced programmers (Most languages today, but not Smalltalk & Perl) Restrictability: a programmer can program effectively in a subset of the full language. (C++: avoids runtime penalties)

Chapter 3 Louden21 Wikipedia moment: Syntactic sugar is a term coined by Peter J. Landin for additions to the syntax of a computer language that do not affect its expressiveness but make it "sweeter" for humans to use. Syntactic sugar gives the programmer (designer, in the case of specification computer languages) an alternative way of coding (specifying) that is more practical, either by being more succinct or more like some familiar notation.Peter J. Landinsyntax computer language programmer

Chapter 3 Louden22 C++ case study Thanks to Bjarne Stroustrup, C++ is not only a great success story, but also the best-documented language development effort in history: –1997: The C++ Programming Language, 3rd Edition (Addison-Wesley). –1994: The Design and Evolution of C++ (Addison-Wesley). –1993: A History of C , SIGPLAN Notices 28(3).

Chapter 3 Louden23 Major C++ design goals OO features: class, inheritance Strong type checking for better compile-time debugging Efficient execution Portable Easy to implement Good interfaces with other tools

Chapter 3 Louden24 Supplemental C++ design goals C compatibility (but not an absolute goal: no gratuitous incompatibilities) Incremental development based on experience. No runtime penalty for unused features. Multiparadigm Stronger type checking than C Learnable in stages Compatibility with other languages and systems

Chapter 3 Louden25 C++ design errors Too big? –C++ programs can be hard to understand and debug –Not easy to implement –Defended by Stroustrup: multiparadigm features are worthwhile No standard library until late (and even then lacking major features) –Stroustrup agrees this has been a major problem