Thanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.

Similar documents
Object typing and subtypes

Logic Programming II & Revision

C++ Yanyan SHEN. slide 1

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

History C++ Design Goals. How successful? Significant constraints. Overview of C++

Subtyping (Dynamic Polymorphism)

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Concepts in Programming Languages

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

The Java Programming Language

Objects, Encapsulation, Inheritance (2)

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Course outline. CSE 341: Programming Languages. Why study programming languages? Course motivation and objectives. 1 lecture: Concepts

Announcements. Scope, Function Calls and Storage Management. Block Structured Languages. Topics. Examples. Simplified Machine Model.

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Introduction. A. Bellaachia Page: 1

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Programmiersprachen (Programming Languages)

Simula 67. Simula and Smalltalk. Comparison to Algol 60. Brief history. Example: Circles and lines. Objects in Simula

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Types and Type Inference

Programming Languages, Summary CSC419; Odelia Schwartz

Com S 541. Programming Languages I

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

CS 242. Fundamentals. Reading: See last slide

Data Abstraction. Hwansoo Han

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

cs242 Kathleen Fisher Reading: Concepts in Programming Languages, Chapter 6 Thanks to John Mitchell for some of these slides.

Chapter 3:: Names, Scopes, and Bindings (cont.)

Seminar in Programming Languages

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

CPS 506 Comparative Programming Languages. Programming Language

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

CMSC 331 Final Exam Section 0201 December 18, 2000

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Chapter 3:: Names, Scopes, and Bindings (cont.)

Lecture Notes on Programming Languages

Functional Programming. Introduction To Cool

CS 360 Programming Languages Interpreters

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Simply-Typed Lambda Calculus

Object Oriented Paradigm

Types and Type Inference

INF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.

Programming Language Concepts 1982, 1987, Outline. Period

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Imperative Programming

Types and Classes. I II From predefined (simple) and user-defined (composite) types via Abstract data types

Concepts of Programming Languages

Storage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage

Programming Languages Third Edition. Chapter 7 Basic Semantics

What about Object-Oriented Languages?

Types, Type Inference and Unification

Scope, Functions, and Storage Management

Programming Languages 2nd edition Tucker and Noonan"

Types for References, Exceptions and Continuations. Review of Subtyping. Γ e:τ τ <:σ Γ e:σ. Annoucements. How s the midterm going?

Informatica 3 Syntax and Semantics

StackVsHeap SPL/2010 SPL/20

Procedure and Object- Oriented Abstraction

Programming Languages (PL)

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

INF 102 CONCEPTS OF PROG. LANGS FUNCTIONAL COMPOSITION. Instructors: James Jones Copyright Instructors.

Combined Object-Lambda Architectures

Concepts Introduced in Chapter 7

CSE 307: Principles of Programming Languages

NOTE: Answer ANY FOUR of the following 6 sections:

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Chapter 9 :: Data Abstraction and Object Orientation

Control in Sequential Languages

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

CS 415 Midterm Exam Spring 2002

Control Abstraction. Hwansoo Han

Functional Languages. Hwansoo Han

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

COS 320. Compiling Techniques

Programming Language Pragmatics

1: Introduction to Object (1)

Recursive Types and Subtyping

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

CSC 533: Organization of Programming Languages. Spring 2005

Lecture 23: Object Lifetime and Garbage Collection

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Imperative Programming Languages (IPL)

INSTITUTE OF AERONAUTICAL ENGINEERING

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg

CS153: Compilers Lecture 11: Compiling Objects

Note 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University

Chapter 10 :: Data Abstraction and Object Orientation

Transcription:

1 CS 242 Thanks! Review John Mitchell Final Exam Wednesday Dec 8 8:30 11:30 AM Gates B01, B03 Teaching Assistants Mike Cammarano TJ Giuli Hendra Tjahayadi Graders Andrew Adams Kenny Lau Vishal Patel and more Tait Larson Aman Naimat Justin Pettit Course Goals There are many programming languages Understand how programming languages work Appreciate trade-offs in language design Be familiar with basic concepts so you can understand discussions about Language features you haven t used Analysis and environment tools Implementation costs and program efficiency Language support for program development Early languages Fortran, Cobol, APL,... Algol family Algol 60, Algol 68, Pascal,, PL/1, Clu, Ada, Modula, Cedar/Mesa,... Functional languages Lisp, FP, SASL, ML, Miranda, Haskell, Scheme, Setl,... Object-oriented languages Smalltalk, Self, Cecil, Modula-3, Eiffel, Sather, C++, Objective C,. Java General Themes in this Course Concurrent languages Actors, Occam,... Pai-Lisp, Proprietary and special purpose languages TCL, Applescript, Telescript,... Postscript, Latex, RTF, Domain-specific language Specification languages CORBA IDL,... Z, VDM, LOTOS, VHDL, Language provides an abstract view of machine We don t see registers, length of instruction, etc. The right language can make a problem easy; wrong language can make a problem hard Could have said a lot more about this Language design is full of difficult trade-offs Expressiveness vs efficiency,... Important to decide what the language is for Every feature requires implementation data structures and algorithms

2 Good languages designed with specific goals (often an intended application) A good language design presents abstract machine, an idealized view of computer C: systems programming Lisp: symbolic computation, automated reasoning FP: functional programming, algebraic laws ML: theorem proving Clu, ML modules: modular programming Simula: simulation Smalltalk: Dynabook, C++: add objects to C Java: set-top box, internet programming Lisp: cons cells, read-eval-print loop FP:?? ML: functions are basic control structure, memory model includes closures and reference cells C: the underlying machine + abstractions Simula: activation records and stack; object references Smalltalk: objects and methods C++:?? Java: Java virtual machine Design Issues Language design involves many trade-offs space vs. time efficiency vs. safety efficiency vs. flexibility efficiency vs. portability static detection of type errors vs. flexibility simplicity vs. "expressiveness" etc These must be resolved in a manner that is consistent with the language design goals preserves the integrity of abstract machine In general, high-level languages/features are: slower than lower-level languages C slower than assembly C++ slower than C Java slower than C++ provide for programs that would be difficult/impossible otherwise Microsoft Word in assembly language? Extensible virtual environment without objects? Concurrency control without semaphores or monitors? Many program properties are undecidable (can't determine statically ) Halting problem nil pointer detection alias detection perfect garbage detection etc. Static type systems detect (some) program errors statically can support more efficient implementations are less flexible than either no type system or a dynamic one Languages are still evolving Object systems Adoption of garbage collection Concurrency primitives; abstract view of concurrent systems Domain-specific languages Network programming Aspect-oriented programming and many other fads Every good idea is a fad until is sticks

3 Summary of the course Lisp Summary Lisp, 1960 Fundamentals lambda calculus denotational semantics functional prog ML and type systems Block structure and activation records Exceptions and continuations Modularity and objects encapsulation dynamic lookup subtyping inheritance Simula and Smalltalk C++ Java Concurrency Successful language Symbolic computation, experimental programming Specific language ideas Expression-oriented: functions and recursion Lists as basic data structures Programs as data, with universal function eval Stack implementation of recursion via "public pushdown list" Idea of garbage collection. Fundamentals Algol Family and ML Grammars, parsing Lambda calculus Denotational semantics Functional vs. Imperative Programming Is implicit parallelism a good idea? Is implicit anything a good idea? Evolution of Algol family Recursive functions and parameter passing Evolution of types and data structuring ML: Combination of Lisp and Algol-like features Expression-oriented Higher-order functions Garbage collection Abstract data types Module system Exceptions Types and Type Checking Types are important in modern languages Program organization and documentation Prevent program errors Provide important information to compiler Type inference Determine best type for an expression, based on known information about symbols in the expression Polymorphism Single algorithm (function) can have many types Overloading Symbol with multiple meanings, resolved at compile time Type inference algorithm Example - fun f(x) = 2+x; > val it = fn : int int How does this work? Assign types to leaves Propagate to internal nodes and generate constraints Solve by substitution Graph for λx. ((plus 2) x) λ @ @ int int x : t + 2 : int int int int real real real t int = int int int (t = int)

4 Block structure and storage mgmt Block-structured languages and stack storage In-line Blocks activation records storage for local, global variables First-order functions parameter passing tail recursion and iteration Higher-order functions deviations from stack discipline language expressiveness => implementation complexity Summary of scope issues Block-structured lang uses stack of activ records Activation records contain parameters, local vars, Also pointers to enclosing scope Several different parameter passing mechanisms Tail calls may be optimized Function parameters/results require closures Closure environment pointer used on function call Stack deallocation may fail if function returned from call Closures not needed if functions not in nested blocks Control Structured Programming Go to considered harmful Exceptions structured jumps that may return a value dynamic scoping of exception handler Continuations Function representing the rest of the program Generalized form of tail recursion Modularity and Data Abstraction Step-wise refinement and modularity History of software design Language support for information hiding Abstract data types Datatype induction Packages and modules Generic abstractions Datatypes and modules with type parameters Design of STL Concepts in OO programming Four main language ideas Encapsulation Dynamic lookup Subtyping Inheritance Why OOP? Extensible abstractions; separate interface from impl Compare oo to conventional (non-oo) lang Can represent encapsulation and dynamic lookup Need inheritance and subtyping as basic constructs Simula 67 First object-oriented language Designed for simulation Later recognized as general-purpose prog language Extension of Algol 60 Standardized as Simula (no 67 ) in 1977 Inspiration to many later designers Smalltalk C++...

5 Objects in Simula Class A procedure that returns a pointer to its activation record Object Activation record produced by call to a class Object access Access any local variable or procedures using dot notation: object. Memory management Objects are garbage collected Simula Begin pg 48-49: user destructors undesirable Smalltalk Major language that popularized objects Developed at Xerox PARC 1970 s (Smalltalk-80) Object metaphor extended and refined Used some ideas from Simula, but very different lang Everything is an object, even a class All operations are messages to objects Very flexible and powerful language Similar to everything is a list in Lisp, but more so Method dictionary and lookup procedure Run-time search; no static type system Independent subtyping and inheritance C++ Design Principles: Goals, Constraints Object-oriented features Some good decisions, some problem areas Classes, Inheritance and Implementation Base class and Derived class (inheritance) Run-time structures: offset known at compile time Subtyping Subtyping principles Abstract base classes Specializing types of public members Multiple Inheritance Examples If circle <: shape, then circle shape circle circle shape shape shape circle C++ compilers recognize limited forms of function subtyping Subtyping with functions class Point { int getx(); virtual Point *move(int); protected:... private:... class ColorPoint: public Point { Inherited, but repeated int getx(); here for clarity int getcolor(); ColorPoint * move(int); void darken(int); protected:... private:... In principle: can have ColorPoint <: Point In practice: some compilers allow, others have not This is covariant case; contravariance is another story Java function subtyping Signature Conformance Subclass method signatures must conform to those of superclass Argument types, Return type, Exceptions: How much conformance is really needed? Java rule Arguments and returns must have identical types, may remove exceptions

6 vtable for Multiple Inheritance Object and classes A C B class A { int x; virtual void f(); class B { int y; virtual void g(); virtual void f(); class C: public A, public B { int z; virtual void f(); C *pc = new C; B *pb = pc; A *pa = pc; Three pointers to same object, but different static types. pa, pc pb δ C object vptr A data vptr B data C data A object B object C-as-A vtbl & C::f 0 C-as-B vtbl & B::g 0 & C::f Offset δ in vtbl is used in call to pb->f, since C::f may refer to A data that is above the pointer pb Call to pc->g can proceed through C-as-B vtbl δ Java Summary Java Summary (II) Objects have fields and methods alloc on heap, access by pointer, garbage collected Classes Public, Private, Protected, Package (not exactly C++) Can have static (class) members Constructors and finalize methods Inheritance Single inheritance Final classes and methods Subtyping Determined from inheritance hierarchy Class may implement multiple interfaces Virtual machine Load bytecode for classes at run time Verifier checks bytecode Interpreter also makes run-time checks type casts array bounds Portability and security are main considerations Concurrency Concurrent programming requires Ability to create processes (threads) Communication Synchronization Attention to atomicity What if one process stops in a bad state, another continues? Language support Synchronous communication Semaphore: list of waiting processes Monitor: synchronized access to private data Concurrency (II) Actors Simple object-based metaphor Concurrent ML Threads, synchronous communication, events Java language Threads: objects from subclass of Thread Communication: shared variables, method calls Synchronization: every object has a lock Atomicity: no explicit support for rollback Java memory model Separate cache for each thread; coherence issues

7 Good Luck! Think about main points of course Homework made you think about certain details What s the big picture? What would you like to remember 5 years from now? Look at homework and sample exams Some final exam problems will resemble homework Some may ask you to use what you learned in this course to understand language combinations or features we did not talk about I hope course will be useful to you in the future Send me email in 1 year, 2 years, 5 years