CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? •...

34
http://xkcd.com/224/

Transcript of CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? •...

Page 1: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

http://xkcd.com/224/

Page 2: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

CS252 Programming Language Paradigms

Prof. Tom Austin San José State University

Fall 2014

Page 3: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

What are some programming languages?

Page 4: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Why are there so many?

•  Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python, PHP) – Databases (SQL)

•  Different design choices. Some concerns: –  Flexibility (Scripting languages) – Type safety (Java, Scala, Haskell) –  Performance (C, C++, Go) – Build time (Go, Rust, D) – Concurrency (Erlang, Go, Rust, D)

Page 5: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Which language is better?

Page 6: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Good language features

•  Simplicity •  Readability and writability •  Learn-ability (familiarity helps here) •  Safety •  Machine independence •  Efficiency (of execution, but also of

compilation) •  Backwards compatibility

Page 7: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

These goals almost always conflict

•  Type systems – prevent bad programs from running – also restrict what the programmer can do

•  Machine-independence and efficient low-level operations are difficult to pair.

•  Good language designs choosing careful compromises for the right set of features.

Page 8: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Why do we make you take a programming 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 9: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

We want to warp your minds.

Page 10: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

These languages will change the way that you think about programming.

That will make you a better Java programmer.

Page 11: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Blub programmers

•  Paul Graham discusses "Blub" programmers: http://www.paulgraham.com/avg.html

•  Hypothetical language midway in the "power continuum". – He defines "power" roughly as being able to do

more with fewer lines of code.

Page 12: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

The Blub Paradox "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 it dictates the way they think about programs." --Paul Graham

Why do I need higher-order functions? My language doesn't have it, and it works just fine!!!

Page 13: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

So what kind of abstractions do different languages give us?

Page 14: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

A little history

WWII: programming meant plugboards

Page 15: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

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

A small, machine language program

Page 16: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Assembly (1950s)

•  Translates mnemonic symbols to machine instructions.

•  Not a higher level – just easier for humans to read. mov ax, 1234h mov bx, ax

Page 17: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

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 18: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Does a formal specification matter?

Page 19: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Type of Abstractions

•  Data – Basic: representation of common data values,

variables to represent memory locations. – Structured: arrays, text files. – Unit: APIs, packages, classes, etc.

•  Control – Basic: "syntactic sugar" x+=10 => x=x+10 – Structured: branch instructions (if statements, etc) – Unit: Similar to Data, but focused on operations.

Page 20: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Languages we will cover (subject to change)

•  Scheme (functional programming) •  Prolog (logical programming) •  JavaScript (event-based programming) •  Ruby (metaprogramming, & because it's cool) •  ANTLR grammars

Page 21: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Administrative Details

•  Green sheet available at http://cs.sjsu.edu/~austin/cs152-fall14/Greensheet.html.

•  Homework assignments will be submitted through Canvas (https://sjsu.instructure.com/)

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

Page 22: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

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 23: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Prerequisites

•  CS 151 or CMPE 135, grade C- or better •  Show me proof of your prerequisite (even

if you are registered for the course). – If you don't provide proof, I will drop you

from the course.

Page 24: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Resources Louden & Lambert, "Programming Languages: Principles and Practice", 3rd ed.

Sitaram, "Teach Yourself Scheme in Fixnum Days". http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html

Page 25: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Grading

• 40% -- Homework assignments • 25% -- Midterm • 25% -- Final • 10% -- Participation (labs)

Page 26: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Participation: Labs

•  Labs are graded as complete/incomplete. •  I generally do not give feedback on your lab

solutions, though I will look at them. •  If you have questions, ask me during the lab.

Page 27: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Office hours

•  MacQuarrie Hall room 216. •  Tuesdays 10:30 – 11:30 am. •  Thursdays 3:30 – 4:30 pm. •  If you need to meet with me another time,

send me an email.

Page 28: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Scheme

Page 29: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

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) •  The list is the primary data structure •  (Famously) minimal language •  We will use the Racket dialect of Scheme

Page 30: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

A bit of scheming

•  Sample list: '(1 2 3 4) – The quote declares this list as data

•  First argument is assumed to be a function – Rest of the list are its arguments – (* 4 3 2 1)

•  car: gets the first element of the list •  cdr: gets the tail of the list.

Page 31: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

$ racket Welcome 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 >

Page 32: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

Before next class

•  Install Racket from http://racket-lang.org/ •  Read chapters 1-2 of Louden & Lambert.

Page 33: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

First homework due September 5th

•  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://cs.sjsu.edu/~austin/cs152-fall14/hw/hw1/ instead.

• Get started now!

Page 34: CS152-Introduction - SJSU Computer Science Department · 2014-08-26 · Why are there so many? • Different domains. – Mobile devices (Objective C) – Web programming (Ruby, Python,

EXTRA CREDIT: Build it, Break it See competition details at https://www.builditbreakit.org/. You can earn up to 15 points of extra credit (5 pts/round). Register with your SJSU email address. Build It Round: 2014.08.28 21:00 EDT - 2014.08.31 21:00 EDT Break It Round: 2014.09.04 21:00 EDT - 2014.09.07 21:00 EDT Fix It Round: 2014.09.12 21:00 EDT - 2014.09.14 21:00 EDT