Python C/C++ Java Perl Ruby

Python C/C++ Java Perl Ruby

Programming Languages Big Ideas for CS 251 • What is a PL? Theory of Programming Languages • Why are new PLs created? Principles of Programming Languages – What are they used for? – Why are there so many? • Why are certain PLs popular? • What goes into the design of a PL? CS251 Programming Languages – What features must/should it contain? Spring 2018, Lyn Turbak – What are the design dimensions? – What are design decisions that must be made? Department of Computer Science Wellesley College • Why should you take this course? What will you learn? Big ideas 2 PL is my passion! General Purpose PLs • First PL project in 1982 as intern at Xerox PARC Java Perl • Created visual PL for 1986 MIT Python masters thesis • 1994 MIT PhD on PL feature Fortran (synchronized lazy aggregates) ML JavaScript • 1996 – 2006: worked on types Racket as member of Church project Haskell • 1988 – 2008: Design Concepts in Programming Languages C/C++ Ruby • 2011 – current: lead TinkerBlocks research team at Wellesley • 2012 – current: member of App Inventor development team CommonLisp Big ideas 3 Big ideas 4 Domain Specific PLs Programming Languages: Mechanical View HTML A computer is a machine. Our aim is to make Excel CSS the machine perform some specifieD acEons. With some machines we might express our intenEons by Depressing keys, pushing OpenGL R buIons, rotaEng knobs, etc. For a computer, Matlab we construct a sequence of instrucEons (this LaTeX is a ``program'') anD present this sequence to IDL the machine. Swift PostScript! – Laurence Atkinson, Pascal Programming Big ideas 5 Big ideas 6 Programming Languages: LinguisEc View Religious Views The use of COBOL cripples the minD; its teaching shoulD, therefore, be A computer language … is a novel formal regarDeD as a criminal offense. – Edsger Dijkstra It is pracEcally impossible to teach gooD programming to stuDents that meDium for expressing iDeas about have had a prior exposure to BASIC: as potenEal programmers they are methoDology, not just a way to get a computer mentally muElateD beyonD hope of regeneraEon. – Edsger Dijstra You're introDucing your stuDents to programming in C? You might as well to perform operaEons. Programs are wriIen for give them a frontal lobotomy! – A colleague of mine people to read, anD only inciDentally for A LISP programmer knows the value of everything, but the cost of nothing. - Alan Perlis machines to execute. I have never met a stuDent who cut their teeth in any of these languages – Harold Abelson and Gerald J. Sussman anD DiD not come away profounDly DamageD anD unable to cope. I mean this reads to me very similarly to teaching someone to be a carpenter by starEng them off with plasEc toy tools anD telling them to go sculpt sanD on the beach. - Alfred Thompson, on blocks languages A language that Doesn't affect the way you think about programming, is not worth knowing. - Alan Perlis Big ideas 7 Big ideas 8 Which Programming/PL Hat Do You Wear? Programming Language EssenEals CS111 Big idea #1: Abstraction Function & ! Function & ! Contract / API Data Abstraction! PrimiEves Data Abstraction! Implementer User / Client Means of CombinaEon Means of AbstracEon Think of the languages you know. What means of abstracEon Do they have? Programming Language Designer Big ideas 9 Big ideas 10 PL Parts Syntax (Form) vs. Semantics (Meaning) Syntax: form of a PL in Natural Language • What a P in a given L look like as symbols? • Concrete syntax vs abstract syntax trees (ASTs) Furiously sleep ideas green colorless. Semantics: meaning of a PL • Dynamic Semantics: What is the behavior of P? What actions does it perform? What values does it produce? Colorless green ideas sleep furiously. – Evaluation rules: what is the result or effect of evaluating each language fragment and how are these composed? Little white rabbits sleep soundly. • Static Semantics: What can we tell about P before running it? – Scope rules: to which declaration does a variable reference refer? – Type rules: which programs are well-typed (and therefore legal)? Pragmatics: implementation of a PL (and PL environment) • How can we evaluate programs in the language on a computer? • How can we optimize the performance of program execution? Big ideas 11 Big ideas 12 Abstract Syntax Tree (AST): This AST abstracts over the Concrete Syntax: Absolute Value FuncEon concrete syntax for the Logo, Absolute Value FuncEon JavaScript, anD Python Logo: to abs :n ifelse :n < 0 [output (0 - :n)] [output :n] end DefiniEons. The other DefiniEons funcEonDeclaraEon woulD have Different ASTs. Javascript: function abs (n) {if (n < 0) return -n; else return n;} body funcDonName params Java: public static int abs (int n) {if (n < 0) return -n; else return n;} abs conDiEonalStatement Python: App Inventor: n test def abs(n): then if n < 0: relaEonalOperaEon return -n return return else: value rand1 value return n lessThan varref intlit arithmeEcOperaEon varref Scheme: (define abs (lambda (n) (if (< n 0) (- n) n))) name rand1 name PostScript: /abs {dup 0 lt {0 swap sub} if} def n 0 n subtract intlit varref value name 0 n Big ideas 13 Big ideas 14 Dynamic SemanEcs Example 1 Dynamic SemanEcs Example 2 What is the meaning of the following expression? What is printeD by the following program? a = 1; (1 + 11) * 10 b = a + 20; print(b); a = 300 print(b); count = 0; fun inc() { count = count + 1; return count; } fun dbl(ignore, x) { return x + x; } print(dbl(inc(), inc()) Big ideas 15 Big ideas 16 Dynamic SemanEcs Example 3 StaEc SemanEcs Example 1: Type Checking Suppose a is an array (or list) containing the three integer values 10, 20, anD 30 Which of the following Java examples can be well-typeD (i.e., pass the type in the following languages. What is the meaning of the following expressions/ checker)? How Do you know? What assumpEons are you making? statements in various languages (the syntax might Differ from what’s shown). A 2 * (3 + 4) a[1] a[3] a[2] = "foo" a[3] = 17 F if (a) { G public boolean f(int i, boolean b) { Java c = a + b; return b && (i > 0); B 2 < (3 + 4) } else { } C c = a * b; Python C 2 < True } H public int g(int i, boolean b) { return i * (b ? 1 : -1); JavaScript D if (a < b) { } Pascal c = a + b; } else { I public int p(int w) { App Inventor c = a * b; if (w > 0) { return 2*w; } } } How Do you Determine the answers??? J public int q(int x) { return x > 0; } E if (a < b) { c = a + b; public int r(int y) { return g(y, y>0); } } else { K c = a > b; public boolean s(int z) { return f(z); } } L Big ideas 17 Big ideas 18 Static Semantics Example 2: Static Semantics and Uncomputability Detecting Loops It is generally impossible to answer any interesEng quesEon about Which of these Python programs has staEc program analysis! inputs for which it loops forever? This is a consequence of Rice’s Theorem (see CS235). def f(x): return x+1 For example, will this program ever: • halt on certain inputs def g(x): def g2(x): while True: return g2(x) • encounter an array index out of bounds error? pass def collatz(x): • throw a NullPointerException? return x while x != 1: if (x % 2) == 0: • access a given object again? x = x/2 • send sensitive information over the network? def h(x): def h2(x): else: • divide by 0? x = 3*x + 1 while x > 0: if x <= 0: return 1 • run out of memory, starting with a given amount available? x = x+1 return x return x else: • try to treat an integer as an array? return h(x+1) Big ideas 19 Big ideas 20 The Church-Turing Thesis anD Turing-Completeness Expressiveness anD Power • About: • Church-Turing Thesis: Computability is the common spirit emboDieD by – ease this collecEon of formalisms. – elegance • This thesis is a claim that is wiDely believeD about the intuiEve noEons of – algorithm anD effecEve computaEon. It is not a theorem that can be clarity proved. – moDularity • Because of their similarity to later computer harDware, Turing machines – abstracEon (CS235) have become the golD stanDarD for effecEvely computable. – ... • Well see in CS251 that Church’s lambDa-calculus formalism is the • Not about: computability founDaEon of moDern programming languages. • Different problems, Different languages • A consequence: programming languages all have the same – Facebook or web browser in assembly language? computaEonal power in term of what they can express. All such languages are saiD to be Turing-complete. Big ideas 21 Big ideas 22 Pragmatics: Raffle App In App Inventor Pragmatics: Metaprogramming hIp://ai2.appinventor.mit.eDu PLs are implementeD in terms of metaprogams = programs that manipulate other programs. Designer Window Blocks Editor This may sounD weirD, but programs are just trees (ASTs), so a metaprogram is just a program that manipulates trees (think a more complex version of CS230 binary tree programs). ImplementaEon strategies: • Interpreta(on: interpret a program P in a source language S in terms of an implementaEon language I. • Transla(on (compila(on): translate a program P in a source language S to a program P’ in a target language T using a translator wriIen in To enter the raffle, text me now with implementaEon language I. an empty message: 339-225-0287 • Embedding: express program P in source language S in terms of Data How harD is this to Do in more tradiEonal structures anD funcEons in implementaEon language I. Development environments for AnDroiD/ iOS? Big ideas 23 Big ideas 24 Metaprogramming: InterpretaEon Metaprogramming: TranslaEon Program in Program in language A A to B translator language B Program in Interpreter Machine M language L for language L on machine M Interpreter Machine M for language B Big ideas 25 on machine M Big ideas 26 Metaprogramming: EmbedDing Metaprogramming: Bootstrapping Puzzles In what language is the gcc C compiler implementeD? How can we write a Java-to-x86 compiler in Java? How can we write a Racket interpreter in Racket? Program in Interpreter Machine M language A for language B embedDed in on machine M language B We’ll learn how to unDerstanD such puzzles! Big ideas 27 Big ideas 28 Metaprogramming: Programming Language Layers PL Dimensions PLs Differ baseD on Decisions language Designers make in many Dimensions.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us