<<

Introductions

• Who am I? Fundamentals of • About you? Programming – What do you want to get out of this class?

Evan Chang

Meeting 1: Welcome

CSCI 5535, Spring 2009 http://www.cs.colorado.edu/~bec/courses/csci5535-s09/ 2

Administrivia Today

• Some historical context http://www.cs.colorado.edu/~bec/courses/csci5535-s09/ • Goals for this course – readings, slides, assignments, etc. • Requirements and grading • Office hours • Course summary – MW 1:30pm-2:30pm? – and by appointment • Convince you that PL is useful – ECOT 621

3 4

Meta-Level Information “Isn’ PL a solved problem?”

• Please interrupt at any time! • PL is an old field within Science

• It’ completely ok to say: • 1920’s: “computer” = “person” – I don’t understand. Please say it another way. • 1936: Church’s (= PL!) – Slow down! • 1937: Shannon’s digital circuit design – Wait, I want to read that! • 1940’s: first digital • 1950’s: (= PL!) • More discussion, less lecture • 1958: LISP (= PL!) • 1960’s: • 1972: Programming • 1981: TCP/IP • 1985: Windows 5 6

1 New and Better ? A Dismal View of PL Research

C++

Java

7 8

Programming Languages Overarching Theme

• Touches most other areas of CS • I assert ( and shall convince you ) that – Theory : DFAs, TMs, language theory (.g., LALR) – Systems : system calls, memory management – Arch : targets, optimizations, stack frames • PL is one of the most vibrant and active – Numerics : FORTRAN, IEEE FP, Matlab – AI : theorem proving, search areas of CS research today – DB : SQL, transactions – It is both theoretical and practical – Networking : packet filters, protocols – It intersects most other CS areas – Graphics : OpenGL, LaTeX, PostScript – Security : buffer overruns, .NET, , PCC, … – Computational Biology : pathway models • You will be able to use PL techniques in – : , development tools your own projects – Human Computer Interaction : development tools

• Both theory (math) and practice (engineering) 9 10

Goal 1

Learn to use PL techniques Goals

12

2 No Useless Memorization Goal 2

• I will not waste your time with useless memorization • This course will cover complex subjects When (not if) you design a • I will teach their details to help you language, it will avoid the understand them the first time mistakes of the past, and you • But you will never have to memorize anything low-level will be able to describe it • Rather, learn to broad concepts formally

13 14

Discussion: Language Design Why so many languages?

• Languages are adopted to fill a void – Enable a previously difficult/impossible application – Orthogonal to language design quality (almost) • Training is the dominant adoption cost – Languages with many users are replaced rarely – But easy to start in a new niche. Examples:

15 16

Why so many languages? Language Paradigms

• Examples: • Imperative – AI: symbolic computation (Lisp, ) – Fortran, Algol, Cobol, C, Pascal – Scientific : high performance (Fortran) • Functional – Lisp, Scheme, ML, Haskell – Business: report generation (COBOL) • Object oriented – Systems Programming: low-level access (C) – , Eiffel, Self, C++, , C#, Javascript – Scripting (, Python, ) • – Distributed Systems: mobile computation (Java) – Prolog – (PHP) • Concurrent – Special purpose languages: … – CSP, dialects of the above languages • Special purpose – TEX, Postscript, TrueType, sh, HTML,

18 19

3 What makes a good language? What are good language features?

• No universally accepted metrics for design

• “A good language is one people use” ?

20 21

Designing good languages is hard Story: The Clash of Two Features

• Goals almost always conflict. • Real story about bad programming • Examples: language design – Safety checks cost something in either • Cast includes famous scientists compilation or time. • ML (’82) functional language with – Type systems restrict in polymorphism and monomorphic exchange for strong guarantees. (i.e., pointers) • Standard ML (’85) innovates by adding polymorphic references • It took 10 years to fix the “innovation”

23 24

Polymorphism (Informal) References in Standard ML

• Code that works uniformly on various types of • Like “ updatable pointers ” in C • Examples of signatures: • Type constructor: τ ref length : α list → int (takes an argument of type “list of α”, x : int ref “x is a pointer to an integer” returns an integer, for any type α) head : α list → α • Expressions: ref : τ → τ ref (allocate a cell to store a τ, like malloc ) • : !e : τ when e : τ ref – generalize all elements of the input type that are not used by (read through a pointer, like *e ) the computation e := e’ with e : τ ref and e’ : τ (write through a pointer, like *e = e’ ) • Works just as you might expect 25 26

4 Reconciling Polymorphism and Polymorphic References: A Major Pain References Consider the following program fragment: • fails to prevent a type error ! • Commonly accepted solution today: Code Type inference – value restriction: generalize only the type of fun id(x) = x id : α → α (for any α) values ! val c = ref id c : (α → α) ref (for any α) • easy to use, simple proof of soundness fun inc(x) = x + 1 inc : int → int – many “failed fixes” c := inc Ok, since c : (int → int) ref • To see what went wrong we needed to (!c) (true) Ok, since c : (bool → bool) ref understand , type systems, polymorphism and references

27 28

Story: Java Bytecode Recall Goal 2

• Java bytecode programs contain subroutines (jsr) that run in the caller’s stack frame ( why? ) • jsr complicates the formal semantics of When (not if) you design a – Several verifier bugs were in code implementing jsr language, it will avoid the – 30% of typing rules, 50% of soundness proof due to jsr mistakes of the past, and you • It is not worth it : – In 650K lines of Java code, 230 subroutines, saving will be able to describe it 2427 , or 0.02% – 13 times more space could be saved by renaming the formally language back to Oak

29 30

Goal 3 Most Important Goal

Understand current PL Have Lots of Fun! research (POPL, PLDI, OOPSLA, TOPLAS, …)

31 32

5 Prerequisites

• “Programming experience” – exposure to various language constructs and their meaning (e.g., CSCI 3155) Requirements – ideal: undergraduate compilers (e.g., CSCI 4555) • “Mathematical maturity” – we’ll use formal notation to describe the meaning of programs

• If you are an undergraduate or from another department, please see me.

34

Assignments Reading and Participation

• Reading and participation (each meeting) • ~2 papers/book chapter, each meeting • Weekly homework (for half semester) – Spark class discussion, post/bring questions • Take-home midterm exam • Final project • Online discussion forum – Post ≥1 substantive comment, question, or answer for each lecture – On moodle.cs.colorado.edu – Due before the next meeting

35 36

Homework and Exam Final Project

• Homework/Problem Sets • Options: – You have one week to do each one – Literature survey – First half of the semester only – project – Some material will be “mathy” – Research project – Collaborate with peers (but acknowledge!) • Write a 5-page paper (conference style) • Give a ~10 minute presentation • Take-Home Midterm Exam • On a topic of your choice – Like a longer homework – Ideal: integrate PL with your research • Pair projects possible if large 37 38

6 Course At-A-Glance

• Part I: Language Specification – Semantics = Describing programs – Evaluation strategies, imperative languages Course Summary – Textbook : Glynn Winskel. The Formal Semantics of Programming Languages. • Part II: Language Design – Types = Classifying programs – Typed λ-calculus, functional languages • Part III: Applications

40

Core Topics Possible Special Topics

• Semantics • Software model checking – Operational semantics • Object-oriented languages • rules for execution on an abstract • useful for implementing a compiler or • Types for low-level languages – Axiomatic semantics • Types for resource management • logical rules for reasoning about the behavior of a program • useful for proving program correctness • Shape analysis – Abstract interpretation • application: program analysis • Types • What do you want to hear about? – λ-calculus • tiny language to study core issues in isolation 41 42

First Topic: Model Checking For Next Time

• Verify properties or find bugs in software • Join the course moodle and introduce • Take an important program yourself (forum discussion for today) – e.g., a device driver • Read the two articles on SLAM • Merge it with a – e.g., no deadlocks, asynchronous IRP handling, BSD – see the website under “Schedule” sockets, transactions, … • Transform the result into a boolean program • Use a model checker to exhaustively explore the resulting space – Result 1: program provably satisfies property – Result 2: program violates property “right here on line 92,376”!

43 44

7