CSE 130 : Fall Programming Languages. Lecture 11: Ranjit Jhala UC San Diego. programming

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

Back to OCaml. Summary of polymorphism. Example 1. Type inference. Example 2. Example 2. Subtype. Polymorphic types allow us to reuse code.

Monday Feb 16, 5pm. solve these equalities. Midterm Thursday Feb 12. covers only ocaml part of the course, assignments 1 through 3.

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

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

Programming Languages

Programming Languages

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

A Programming Language. A different language g is a different vision of life. CSE 130 : Fall Two variables. L1: x++; y--; (y=0)?

News. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes

A Programming Language. A different language g is a different vision of life. CSE 130 : Spring Two variables. L1: x++; y--; (y=0)?

Programming Languages

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name?

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

Programming Languages. So why study PL? A Programming Language. A different language is a different vision of life. CSE 130 : Spring 2015

Programming Languages. So why study PL? A Programming Language. A different language is a different vision of life. CSE 130 : Fall 2015

Programming Languages

CSE 130 Programming Languages. Lecture 3: Datatypes. Ranjit Jhala UC San Diego

Programming Languages

Recap: ML s Holy Trinity. Story So Far... CSE 130 Programming Languages. Datatypes. A function is a value! Next: functions, but remember.

Programming Languages

CSE 130 Programming Languages. Datatypes. Ranjit Jhala UC San Diego

So what does studying PL buy me?

Programming Languages

Programming Languages

Programming Languages

Algorithms and Programming I. Lecture#12 Spring 2015

Programming Languages

CS252 Advanced Programming Language Principles. Prof. Tom Austin San José State University Fall 2013

Programming Languages

Quiz. Programming Languages. CSE 130 : Fall Lecture 16: Static Types for Objects. Ranjit Jhala UC San Diego

MapReduce, Hadoop and Spark. Bompotas Agorakis

Programming Languages. Example 5. Example 4. CSE 130 : Fall type, can reuse code for all types! let rec cat l = match l with

Big Data Hadoop Stack

CSE 544 Principles of Database Management Systems. Alvin Cheung Fall 2015 Lecture 10 Parallel Programming Models: Map Reduce and Spark

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

SCHEME AND CALCULATOR 5b

Intro. Scheme Basics. scm> 5 5. scm>

CS Lecture 6: Map and Fold. Prof. Clarkson Fall Today s music: Selections from the soundtrack to 2001: A Space Odyssey

Programming Languages

Programming Languages. Programming with λ-calculus. Lecture 11: Type Systems. Special Hour to discuss HW? if-then-else int

Smalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)

CSE : Python Programming

Introduction to MapReduce

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

New Programming Paradigms

CS6030 Cloud Computing. Acknowledgements. Today s Topics. Intro to Cloud Computing 10/20/15. Ajay Gupta, WMU-CS. WiSe Lab

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CS457/557 Functional Languages

Recall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean?

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

Func%onal Programming in Scheme and Lisp

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

Week - 01 Lecture - 04 Downloading and installing Python

CSE 130 [Spring 2014] Programming Languages

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012

Func%onal Programming in Scheme and Lisp

CS1110 Lab 1 (Jan 27-28, 2015)

CS 11 Haskell track: lecture 1

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

The Haskell HOP: Higher-order Programming

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

CSE 374: Programming Concepts and Tools. Eric Mullen Spring 2017 Lecture 4: More Shell Scripts

FUNCTIONAL PROGRAMMING

Programming Languages

SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012

Chapter 11 :: Functional Languages

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

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7

Typical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated

CSE 341: Programming Languages

Introduction to computers and Python. Matthieu Choplin

CS312: Programming Languages. Lecture 21: JavaScript

Introduction to programming with Python

Project 2: Scheme Interpreter

Introduction to Computer Vision Laboratories

Lecturer: William W.Y. Hsu. Programming Languages

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

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

Recap: ML s Holy Trinity

First Programming Language in CS Education The Arguments for Scala

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

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

Programming Languages Lecture 15: Recursive Types & Subtyping

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

CS 360 Programming Languages Interpreters

Introduction to MapReduce. Adapted from Jimmy Lin (U. Maryland, USA)

Dynamically-typed Languages. David Miller

CS Lecture 6: Map and Fold. Prof. Clarkson Spring Today s music: Selections from the soundtrack to 2001: A Space Odyssey

News. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values

Environment Diagrams. Administrivia. Agenda Step by Step Environment Diagram Stuff. The Rules. Practice it s on! What are The Rules?

CS 177 Recitation. Week 1 Intro to Java

Functional Programming

Variables, expressions and statements

Using Data From Quandl in EViews

COSE212: Programming Languages. Lecture 4 Recursive and Higher-Order Programming

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

STATS Data Analysis using Python. Lecture 7: the MapReduce framework Some slides adapted from C. Budak and R. Burns

Transcription:

CSE 130 : Fall 2009 Programming Languages News Lecture 11: Hello Python Ranjit Jhala UC San Diego What s the point of all this? Final words on functional programming g

Advantages of functional progs Functional programming more concise one line of lisp can replace 20 lines of C (quote from http://www.ddj.com/dept/architect/184414500?pgno=3) Recall reverse function: let reverse = fold (::) [];; How many lines in C, C++? Better reasoning about Programs No side effects Same inputs return same outputs So, can safely reorder computations So, can also parallelize computations An example: Map/Reduce Scalable data processing: MapReduce programming model Hadoop [Yahoo], Hive [Facebook], Dryad [MSR] Programming model based on map, fold apply a function on each data element (map) aggregate the results (fold) Functional easy parallelism scalable So what? Form the authors: Inspired by similar primitives in LISP and other languages http://labs.google.com/papers/mapreduce-osdi04-slides/index-auto-0003.html g p p p Programmers who only know Java/C/C++ would probably not have come up with this idea For more, take Prof. Vahdat s CSE 124

Remember Say hello to Python Free your mind -Morpheus Recap of the course so far 4+ weeks of functional with OCaml Next: 3 weeks of OO with Python OO at the highest level What is OO programming?

OO at the highest level What is OO programming? Answer: Objects message sends dynamic dispatch Just to whet your appetite Say we have objects, like cars, ducks, pig, cell_phones Say we have a message name: make_some_noise Just to whet your appetite Each object has its own implementation for make_some_noise: these are traditionally called methods. Oh btw... What s the difference between message What s the difference between message and method... car: vroom vroom, pig : oink oink, duck: quack quack Can send make_some_noise to any object. Depending on the actually run-time object, we ll get a different noise!

Oh btw... What s the difference between message and method... Message is just the name of the message, method is the implementation ti Message is the interface / prototype of the method. OO programming Message: the name of an operation Method: the implementation of an operation Dynamic dispatch: dynamic type of object determines which method is run for given message send These are the core ideas of OO This brings us to Python... OCaml/Python comparison We ll use Python as our vehicle for OO programming Fun and useful language Let s compare with OCaml along some of the dimensions we saw last time PL paradigm Basic unit Types DataModel ML Pth Python

Python Python has a very relaxed philosophy if something "can be done" then it is allowed. Dynamic types + Everything is an object very flexible very intuitive code No static types No static type system to "prohibit" operations. No more of the compiler giving you tricky error messages! No static types: but what instead? Dynamic typing At runtime, every "operation" is translated to a method call on the appropriate object. If the object supports the method, then the computation proceeds. Duck-typing: if it looks like a duck, quacks like a duck, then it is a duck! Dynamic typing This loose, comfortable, free-style style, philosophy is at the heart of python. But... beware, you can get burned with this flexibility... Q: how many times did OCaml complain to you statically about something that was NOT a bug?

Similarities to ML Uniform model everything is an object, including functions Pass functions around functions are objects! Supports functional programming map and fold Other cool things about Python A lot of stuff that you may first think is a "language feature" is actually just translated under the hood to a method call... Very widely used, supported. Has libraries for all sorts of things. Ok, let s start playing with Python! Like Perl, python is a "managed" or "interpreted" language that runs under the python environment, i.e. not compiled to machine code. Makes it convenient to rapidly write, check-in and test t code! Ways to run Python code At an interactive Python prompt like "read-eval-print" loop of ML As shell scripts As stand-alone programs run from the shell.

Let s fire it up! Ok, let s give it a try... See lec11.py file for the rest...