cs 152: programming language paradigms · cs152-day01-introduction author: thomas h. austin created...

41
http://xkcd.com/224/

Upload: others

Post on 22-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

http://xkcd.com/224/

Page 2: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

CS 152: Programming Language Paradigms

Prof. Tom AustinSan José State University

Page 3: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

What are someprogramming languages?

Page 4: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Taken from http://pypl.github.io/PYPL.htmlJanuary 2016

Page 5: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Why are there so many?

Page 6: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Different domains

Page 7: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Different design choices

• Flexibility• Type safety• Performance• Build time• Concurrency

Page 8: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Which language is better?

Page 9: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Good language features

• Simplicity• Readability• Learn-ability• Safety• Machine independence• Efficiency

Page 10: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

These goals almost always conflict

Page 11: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Conflict: Type Systems

Stop "bad" programs… but ...

restrict the programmer

Page 12: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Why do we make you take aprogramming languages course?

• You might use one of these languages.• Perhaps one of these languages is the

language of the future (whatever that means).• You might see similar languages in your job.• Somebody made us take one, so now we want

to make you suffer too.• But most of all…

Page 13: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

We want to warp your minds.

Page 14: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Course goal: change the way that you think about programming.

That will make you a better Javaprogrammer.

Page 15: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

The "Blub" paradox

Why do I needhigher order functions?

My language doesn't havethem, and it works

just fine!!!

Page 16: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

"As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down…[Blub programmers are] satisfied with whatever language they happen to use, because itdictates the way they think about programs."--Paul Grahamhttp://www.paulgraham.com/avg.html

Page 17: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

So what kind of abstractions do different languages give us?

Page 18: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Data Abstractions

• Representation of common data values• Variables to represent memory locations.• Structures: arrays, text files, etc.• Organizational units:– APIs– packages– classes

Page 19: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Control Abstractions

• "Syntactic sugar"x+=10 => x=x+10

• Branch instructions– if statements– while loops

Page 20: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

A little history

WWII: programming meant plugboards

Page 21: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Von Neumann (late 1940s) created a permanently hardwired general purpose instruction set.

A small, machine language program

Page 22: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Assembly (1950s)

• Translates mnemonic symbols to machine instructions.

• Not a higher level – just easier for humans to read.

mov ax, 1234hmov bx, ax

Page 23: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Higher-level languages

• Fortran (1950s):– Algebraic notation, floating point math

• Algol (1960):–Machine independence (via compiler)– Control structures: loops, procedures, if statements– Formal specification

Page 24: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Does a formal specification matter?

Page 25: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Languages we will cover(subject to change)

Page 26: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Administrative Details

• Green sheet: http://www.cs.sjsu.edu/~austin/cs152-fall18/Greensheet.html.

• Homework submitted through Canvas: https://sjsu.instructure.com/

• Academic integrity policy:http://info.sjsu.edu/static/catalog/integrity.html

Page 27: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Schedule

• The class schedule is available through Canvas• Late homeworks will not be accepted• Check the schedule before every class• Check the schedule before every class• And finally, CHECK THE SCHEDULE

BEFORE EVERY CLASS.

Page 28: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Prerequisites

•CS 151 or CMPE 135,grade C- or better•Show me proof–If you don't, I will drop you.

Page 29: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Resources

Dorai Sitaram"Teach Yourself Schemein Fixnum Days".http://ds26gte.github.io/tyscheme/

Other references TBD.

Page 30: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Grading

• 30% -- Homework assignments (individual work)

• 20% -- Class project (team work)• 20% -- Midterm• 20% -- Final• 10% -- Participation (labs and drills)

Page 31: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Participation: Labs

• No feedback given (usually)• I will look at them• If you have questions, ask me

Page 32: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Homework

• Done individually.• You may discuss the assignment

with others.• Do your own work!

Page 33: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

How to fail yourself and your friend

If two of you turn in similar assignments:

you both get a 0

Page 34: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Project

• Work in groups of up to four people.• Goal: Build an interpreter.• Use Java and ANTLR

Page 35: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Office hours

•MacQuarrie Hall room 216–Phone being fixed•Mondays & Wednesdays, 10-11am

Page 36: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Racket/Scheme

Page 37: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

What is Scheme?

• A functional language– Describe what things are, not how to do them.–More mathematical compared to imperative langs.

• A dialect of Lisp (List Processing)• (Famously) minimal language• Racket is a dialect of Scheme

Page 38: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Symbolic Expressions(s-expressions)

The single datatype in Scheme. Includes:• Primitive types: booleans, numbers,

characters, and symbols.• Compound data types: strings, vectors, pairs,

and of course…

LISTS!!!

Page 39: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

$ racketWelcome to Racket v6.0.1.> '(1 2 3 4)'(1 2 3 4)> (car '(1 2 3 4))1> (cdr '(1 2 3 4))'(2 3 4)> (+ 1 (* 2 4) (- 5 1))13>

Quote indicates list is data

First element is assumed to be a

function

Page 40: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

Before next class

• Install Racket from http://racket-lang.org/• Read chapters 1-2 of Teach Yourself

Scheme.• Read Paul Graham's "Beating the

Averages" article. http://www.paulgraham.com/avg.html

Page 41: CS 152: Programming Language Paradigms · CS152-Day01-Introduction Author: Thomas H. Austin Created Date: 8/20/2018 7:39:38 PM

First homework due June 18th

• This assignment is designed to get you up and running with Racket.• Available in Canvas.–If you don't have access to Canvas, see

http://www.cs.sjsu.edu/~austin/cs152-summer18/hw/hw1/ instead.

• Get started now!