CMSC 330: Organization of Programming Languages. Administrivia

Similar documents
! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

CMSC 330: Organization of Programming Languages. Administrivia

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

CMSC 330: Organization of Programming Languages

Course Goal CMSC 330: Organization of Programming Languages. All Languages Are (Kind of) Equivalent. Studying Programming Languages.

Concepts of Programming Languages

Com S 541. Programming Languages I

Programming Languages 2nd edition Tucker and Noonan"

CMSC 330: Organization of Programming Languages

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

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

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

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

CSCI-GA Scripting Languages

Seminar in Programming Languages

Programming Languages, Summary CSC419; Odelia Schwartz

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

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

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

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

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

CS 314 Principles of Programming Languages

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

CS558 Programming Languages

Simply-Typed Lambda Calculus

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

CS457/557 Functional Languages

Computer Science Seminar. Whats the next big thing? Ruby? Python? Neither?

CMSC 330: Organization of Programming Languages. Operational Semantics

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

What is a programming language?

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

CS 242. Fundamentals. Reading: See last slide

CMSC 331 Final Exam Section 0201 December 18, 2000

Chapter 11 :: Functional Languages

Functional Programming. Big Picture. Design of Programming Languages

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

CS 415 Midterm Exam Spring 2002

Concepts of Programming Languages

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE : Fall 2017

Functional Programming

CSCI 3136 Principles of Programming Languages

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2013

More Lambda Calculus and Intro to Type Systems

The role of semantic analysis in a compiler

Programming Languages

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

Programming language design and analysis

CMSC 132: Object-Oriented Programming II. Administrivia

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

Chapter 1. Preliminaries

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

CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

So what does studying PL buy me?

CS A331 Programming Language Concepts

SOFTWARE ARCHITECTURE 6. LISP

Principles of Programming Languages. Lecture Outline

CS101 Introduction to Programming Languages and Compilers

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

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

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

CS558 Programming Languages

Programming Language Pragmatics

Programming Languages

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

CS 6371: Advanced Programming Languages

CS558 Programming Languages

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

CS 3813/718 Fall Python Programming. Professor Liang Huang.

Semantic Analysis. Lecture 9. February 7, 2018

COSE212: Programming Languages. Lecture 0 Course Overview

MIDTERM EXAMINATION. CSE 130: Principles of Programming Languages. Professor Goguen. February 16, points total

Introduction. A. Bellaachia Page: 1

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2014

Welcome to CS 135 (Winter 2018)

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Compiler Construction D7011E

1DL321: Kompilatorteknik I (Compiler Design 1)

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

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Introduction CMSC 330: Organization of Programming Languages. Books on Ruby. Applications of Scripting Languages

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

Key components of a lang. Deconstructing OCaml. In OCaml. Units of computation. In Java/Python. In OCaml. Units of computation.

G Programming Languages - Fall 2012

Principles of Compiler Construction ( )

OCaml Data CMSC 330: Organization of Programming Languages. User Defined Types. Variation: Shapes in Java

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Lecture #23: Conversion and Type Inference

Programming Paradigms

NOTE: Answer ANY FOUR of the following 6 sections:

Functional Programming Principles in Scala. Martin Odersky

First Programming Language in CS Education The Arguments for Scala

Installation Download and installation instructions can be found at

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)

Transcription:

CMSC 330: Organization of Programming Languages Administrivia 1

Course Goal Learn how programming languages work Broaden your language horizons Different programming languages Different language features and tradeoffs Ø Useful programming patterns Study how languages are described / specified Mathematical formalisms Study how languages are implemented What really happens when I write x.foo( )? Ø (CMSC 430 goes much further) 2

Course Subgoals Learn some fundamental programminglanguage concepts Regular expressions Automata theory Context free grammars Computer security Improve programming skills Practice learning new programming languages Learn how to program in a new style 3

Syllabus Dynamic/ Scripting languages (Ruby) Functional programming (OCaml) Scoping, type systems, parameter passing Regular expressions & finite automata Context-free grammars & parsing Lambda Calculus MYSTERY TOPIC Secure programming Comparing language styles; other topics 4

Calendar / Course Overview Tests 4 quizzes, 2 midterm exams, 1 final exam Clicker Quizzes In class, graded, during the lectures Projects Project 1 Ruby Project 2-4 OCaml (and parsing, automata) Ø P2 and P4 are split in two parts Project 5 Mystery topic Project 6 Security 5

Clickers Turning Technology clicker or Phone App is required. Subscription is free. You can get any of LCD, NXT, or QT2 models 6

Quiz time! According to IEEE Spectrum Magazine which is the top programming language of 2017? A. Java B. PHP C. C D. Python 7

Quiz time! According to IEEE Spectrum Magazine which is the top programming language of 2017? A. Java B. PHP C. C D. Python 8

Quiz time! 9

Discussion Sections Lectures introduce the course content Discussion sections will deepen understanding These are smaller, and thus can be more interactive Oftentimes discussion section will consist of programming exercises Bring your laptop to discussion Be prepared to program: install the language in question on your laptop, or remote shell into Grace There will also be be quizzes, and some lecture material in discussion sections Quizzes cover non-programming parts of the class 10

Project Grading You have accounts on the Grace cluster Projects will be graded using the submit server Software versions on these machines are canonical Develop programs on your own machine Generally results will be identical on Dept machines Your responsibility to ensure programs run correctly on the grace cluster See web page for Ruby, OCaml, etc. versions we use, if you want to install at home We will provide a VM soon 11

Rules and Reminders Use lecture notes as your text Supplement with readings, Internet You will be responsible for everything in the notes, even if it is not directly covered in class! Keep ahead of your work Get help as soon as you need it Ø Office hours, Piazza (email as a last resort) Don t disturb other students in class Keep cell phones quiet No laptops / tablets in class Ø Except for taking notes (please sit in back of class) 12

Academic Integrity All written work (including projects) must be done on your own Do not copy code from other students Do not copy code from the web Do not post your code on the web We use similarity testing tools; cheaters are caught Work together on high-level project questions Do not look at/describe another student s code If unsure, ask an instructor! Work together on practice exam questions 13

CMSC 330: Organization of Programming Languages Overview 14

All Languages Are (Kind of) Equivalent A language is Turing complete if it can compute any function computable by a Turing Machine Essentially all general-purpose programming languages are Turing complete I.e., any program can be written in any programming language Therefore this course is useless?! Learn only 1 programming language, always use it 15

Studying Programming Languages Will make you a better programmer Programming is a human activity Ø Features of a language make it easier or harder to program for a specific application Ideas or features from one language translate to, or are later incorporated by, another Ø Many design patterns in Java are functional programming techniques Using the right programming language or style for a problem may make programming Ø Easier, faster, less error-prone 16

Studying Programming Languages Become better at learning new languages A language not only allows you to express an idea, it also shapes how you think when conceiving it Ø There are some fundamental computational paradigms underlying language designs that take getting used to You may need to learn a new (or old) language Ø Paradigms and fads change quickly in CS Ø Also, may need to support or extend legacy systems 17

Changing Language Goals 1950s-60s Compile programs to execute efficiently Language features based on hardware concepts Ø Integers, reals, goto statements Programmers cheap; machines expensive Ø Computation was the primary constrained resource Ø Programs had to be efficient because machines weren t Note: this still happens today, just not as pervasively 18

Changing Language Goals Today Language features based on design concepts Ø Encapsulation, records, inheritance, functionality, assertions Machines cheap; programmers expensive Ø Scripting languages are slow(er), but run on fast machines Ø They ve become very popular because they ease the programming process The constrained resource changes frequently Ø Communication, effort, power, privacy, Ø Future systems and developers will have to be nimble 19

Language Attributes to Consider Syntax What a program looks like Semantics What a program means (mathematically) Paradigm How programs tend to be expressed in the language Implementation How a program executes (on a real machine) 20

Syntax The keywords, formatting expectations, and grammar for the language Differences between languages usually superficial Ø C / Java if (x == 1) { } else { } Ø Ruby Ø OCaml if x == 1 else end if (x = 1) then else Differences initially annoying; overcome with experience Concepts such as regular expressions, context-free grammars, and parsing handle language syntax 21

Semantics What does a program mean? What does it do? Same syntax may have different semantics in different languages! Physical Equality Structural Equality Java a == b a.equals(b) C a == b *a == *b Ruby a.equal?(b) a == b OCaml a == b a = b Can specify semantics informally (in prose) or formally (in mathematics) 22

Why Formal Semantics? Textual language definitions are often incomplete and ambiguous Leads to two different implementations running the same program and getting a different result! A formal semantics is basically a mathematical definition of what programs do Benefits: concise, unambiguous, basis for proof We will consider operational semantics Consists of rules that define program execution Basis for implementation, and proofs that programs do what they are supposed to 24

Paradigm There are many ways to compute something Some differences are superficial Ø For loop vs. while loop Some are more fundamental Ø Recursion vs. looping Ø Mutation vs. functional update Ø Manual vs. automatic memory management Language s paradigm favors some computing methods over others. This class: - Imperative - Logic - Functional - Scripting/dynamic 25

Imperative Languages Also called procedural or von Neumann Building blocks are procedures and statements Programs that write to memory are the norm int x = 0; while (x < y) x = x + 1; FORTRAN (1954) Pascal (1970) C (1971) 26

Functional (Applicative) Languages Favors immutability Variables are never re-defined New variables a function of old ones (exploits recursion) Functions are higher-order Passed as arguments, returned as results LISP (1958) ML (1973) Scheme (1975) Haskell (1987) OCaml (1987) 27

OCaml A mostly-functional language Has objects, but won t discuss (much) Developed in 1987 at INRIA in France Dialect of ML (1973) Natural support for pattern matching Generalizes switch/if-then-else very elegant Has full featured module system Much richer than interfaces in Java or headers in C Includes type inference Ensures compile-time type safety, no annotations 28

A Small OCaml Example intro.ml: let greet s = List.iter (fun x -> print_string x) [ hello, ; s; "!\n ] $ ocaml Objective Caml version 3.12.1 # #use "intro.ml";; val greet : string -> unit = <fun> # greet "world";; Hello, world! - : unit = () 29

Logic-Programming Languages Also called rule-based or constraint-based Program rules constrain possible results Evaluation = constraint satisfaction = search A :- B If B holds, then A holds ( B implies A ) Ø append([], L2, L2). Ø append([x Xs],Ys,[X Zs]) :- append(xs,ys,zs). PROLOG (1970) Datalog (1977) Various expert systems 30

Object-Oriented Languages Programs are built from objects Objects combine functions and data Ø Often into classes which can inherit class C { int x; int getx() {return x;} } class D extends C { } Base may be either imperative or functional Smalltalk (1969) C++ (1986) OCaml (1987) Ruby (1993) Java (1995) 31

Dynamic (Scripting) Languages Rapid prototyping languages for common tasks Traditionally: text processing and system interaction Scripting is a broad genre of languages Base may be imperative, functional, OO Increasing use due to higher-layer abstractions Originally for text processing; now, much more sh (1971) perl (1987) Python (1991) Ruby (1993) #!/usr/bin/ruby while line = gets do csvs = line.split /,/ if(csvs[0] == 330 ) then... 32

Ruby An imperative, object-oriented scripting language Created in 1993 by Yukihiro Matsumoto (Matz) Ruby is designed to make programmers happy Core of Ruby on Rails web programming framework (a key to its popularity) Similar in flavor to many other scripting languages Much cleaner than perl Full object-orientation (even primitives are objects!) 33

A Small Ruby Example intro.rb: def greet(s) 3.times { print Hello, } print #{s}!\n end % irb # you ll usually use ruby instead irb(main):001:0> require "intro.rb" => true irb(main):002:0> greet("world") Hello, Hello, Hello, world! => nil 34

Theme: Software Security Security is a big issue today Features of the language can help (or hurt) C/C++ lack of memory safety leaves them open for many vulnerabilities: buffer overruns, use-after-free errors, data races, etc. Type safety is a big help, but so are abstraction and isolation, to help enforce security policies, and limit the damage of possible attacks Secure development requires vigilance Do not trust inputs unanticipated inputs can effect surprising results! Therefore: verify and sanitize 36

Beyond Paradigm Important features Regular expression handling Objects Ø Inheritance Closures/code blocks Immutability Tail recursion Pattern matching Ø Unification Abstract types Garbage collection Declarations Explicit Implicit Type system Static Polymorphism Inference Dynamic Type safety 38

Implementation How do we implement a programming language? Put another way: How do we get program P in some language L to run? Two broad ways Compilation Interpretation 39

Compilation def greet(s) print("hello, ) print(s) print("!\n ) end 11230452 23230456 01200312 world Hello, world! Source program translated ( compiled ) to another language Traditionally: directly executable machine code Generating code from a higher level interface is also common (e.g., JSON, RPC IDL) 40

Interpretation def greet(s) print("hello, ) print(s) print("!\n ) end Hello, world! world Interpreter executes each instruction in source program one step at a time No separate executable 41

Architecture of Compilers, Interpreters Source Parser Static Analyzer Intermediate Representation Front End Back End Compiler / Interpreter 42

Front Ends and Back Ends Front ends handle syntax Parser converts source code into intermediate format ( parse tree ) reflecting program structure Static analyzer checks parse tree for errors (e.g., erroneous use of types), may also modify it Ø What goes into static analyzer is language-dependent! Back ends handle semantics Compiler: back end ( code generator ) translates intermediate representation into object language Interpreter: back end executes intermediate representation directly 43

Compiler or Intepreter? gcc Compiler C code translated to object code, executed directly on hardware (as a separate step) javac Compiler Java source code translated to Java byte code java Interpreter Java byte code executed by virtual machine sh/csh/tcsh/bash Interpreter commands executed by shell program 44

Compilers vs. Interpreters Compilers Generated code more efficient Heavy Interpreters Great for debugging Fast start time (no compilation), slow execution time In practice General-purpose programming languages (e.g. C, Java) are often compiled, although debuggers provide interpreter support Scripting languages and other special-purpose languages are interpreted, even if general purpose 45

Summary Programming languages vary in their Syntax Semantics Style/paradigm Implementation They are designed for different purposes And goals change as the computing landscape changes, e.g., as programmer time becomes more valuable than machine time Ideas from one language appear in others 50