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? SOLUTIONS • Why are certain PLs popular? • What goes into the design of a PL? CS251 Programming Languages – What features must/should it contain? Spring 2019, 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 C# • 2012 – current: member of App Inventor development team Scala CommonLisp Big ideas 3 Big ideas 4 Domain Specific PLs (DSLs) Programming Languages: Mechanical View Excel HTML A computer is a machine. Our aim is to make CSS the machine perform some specified acGons. With some machines we might express our OpenGL LaTeX intenGons by depressing keys, pushing buKons, rotaGng knobs, etc. For a computer, Matlab we construct a sequence of instrucGons (this Digital Amati R is a ``program'') and present this sequence to JINJA the machine. IDL Swift PostScript! – Laurence Atkinson, Pascal Programming Big ideas 5 Big ideas 6 Programming Languages: LinguisGc 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 pracGcally impossible to teach good programming to students that medium for expressing ideas about have had a prior exposure to BASIC: as potenGal programmers they are methodology, not just a way to get a computer mentally muGlated beyond hope of regeneraGon. – Edsger Dijstra You're introducing your students to programming in C? You might as well to perform operaGons. Programs are wriKen 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 starGng them off with plasGc toy tools and telling them to go sculpt sand on the beach. - John Haugeland, 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 Paradigms • Impera've (e.g. C, Python): ComputaGon is step-by-step execuGon on a CS111 Big idea #1: Abstraction stateful abstract machine involving memory slots and mutable data structures. Function & ! • Func'onal, func'on-oriented (e.g Racket, ML, Haskell): ComputaGon is Function & ! Contract / API Data Abstraction! expressed by composing funcGons that manipulate immutable data. Data Abstraction! Implementer • Object-oriented (e.g. Simula, Smalltalk, Java): ComputaGon is expressed in User / Client terms of stateful objects that communicate by passing messages to one another. • Logic-oriented (e.g. Prolog): ComputaGon is expressed in terms of declaraGve relaGonships. Note: In pracGce, most PLs involve mulGple paradigms. E.g. • Python supports funcGonal features (map, filter, list comprehensions) and objects • Racket and ML have imperaGve features. Programming Language Designer Big ideas 9 Big ideas 10 Paradigm Example: Quicksort PL Dimensions PLs differ based on decisions language designers make in many dimensions. E.g.: void qsort(int a[], int lo, int hi) { quicksort :: Ord a => [a] -> [a] int h, l, p, t; quicksort [] = [] • First-class values: what values can be named, passed as arguments to quicksort (p:xs) = if (lo < hi) { funcGons, returned as values from funcGons, stored in data structures. l = lo; (quicksort lesser) Which of these are first-class in your favorite PL: arrays, funcGons, variables? h = hi; ++ [p] p = a[hi]; ++ (quicksort greater) • Naming: Do variables/parameters name expressions, the values resulGng where do { lesser = filter (< p) xs from evaluaGng expressions, or mutable slots holding the values from while ((l < h) && (a[l] <= p)) greater = filter (>= p) xs evaluaGng expressions? How are names declared and referenced? What l = l+1; while ((h > l) && (a[h] >= p)) determines their scope? h = h-1; if (l < h) { • State: What is mutable and immutable; i.e., what enGGes in the language t = a[l]; (variables, data structures, objects) can change over Gme. a[l] = a[h]; a[h] = t; FuncGonal Style (in Haskell) • Control: What constructs are there for control flow in the language, e.g. } } while (l < h); condiGonals, loops, non-local exits, excepGon handling, conGnuaGons? a[hi] = a[l]; • Data: What kinds of data structures are supported in the language, including a[l] = p; products (arrays, tuples, records, dicGonaries), sums (opGons, oneofs, variants), sum-of-products, and objects. qsort( a, lo, l-1 ); ImperaGve Style qsort( a, l+1, hi ); (in C; Java would be similar) • Types: Are programs staGcally or dynamically typed? What types are } } Big ideas 11 expressible? Big ideas 12 Why study PL? Administrivia • Crossroads of CS • Approach problems as a language designer. • Schedule, psets, quizzes, lateness policy, etc.: – "A good programming language is a conceptual universe for thinking about see http://cs.wellesley.edu/~cs251/. programming” -- Alan Perlis • Do (most of) PS0 tonight – Evaluate, compare, and choose languages – Fill out “get to know you” Introze introduction. – Become beKer at learning new languages – Review course syllabus and policies – Become a beKer programmer by leveraging powerful features (we’ll go over these tomorrow) (first-class funcGons, tree recursion, sum-of-product datatypes, paKern – Read Wed slides on “big-step semantics” of Racket matching) – Install Dr. Racket – You probably won’t design a general-purpose PL, but might design a DSL • PS1 is available; due next Friday. Start it this week! – view API design as language design • Ask: • Credit/non is a bad idea for 251. Talk to me first! – Why are PLs are the way they are? • Visit me in office hours before next Friday! – How could they (or couldn't they) be beKer? – What is the cost-convenience trade-off for feature X? Big ideas 13 Big ideas 14 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 15 Big ideas 16 Abstract Syntax Tree (AST): This AST abstracts over the Concrete Syntax: Absolute Value FuncGon concrete syntax for the Logo, Absolute Value FuncGon JavaScript, and Python Logo: to abs :n ifelse :n < 0 [output (0 - :n)] [output :n] end definiGons. The other definiGons funcGonDeclaraGon would have different ASTs. Javascript: function abs (n) {if (n < 0) return -n; else return n;} body funcLonName params Java: public static int abs (int n) {if (n < 0) return -n; else return n;} abs condiGonalStatement Python: App Inventor: n test def abs(n): then if n < 0: relaGonalOperaGon return -n return return else: value rand1 value return n lessThan varref intlit arithmeGcOperaGon varref Scheme/Racket: (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 17 Big ideas 18 Dynamic SemanGcs Example 1 Dynamic SemanGcs Example 2 What is the meaning of the following expression? What is printed by the following program? (1 + 11) * 10 a = 1; Here are some possible answers. What execuGon models give rise to these answers? b = a + 20; Some possible answers: print(b); 21 21 21 21 • 120 (regular interpretaGon of numbers, operators) a = 300 21 21 320 320 • 1000 (binary numbers, regular operators) print(b); 4 2 3 2 • 0 (“+” means “minus”, “*” means “plus”) • 111…1 (30 1s; “+” means “convert to string and concatenate”; count = 0; * means “repeated concatenaGon”) fun inc() { count = count + 1; return count; } • 13 (number of characters in string) fun dbl(ignore, x) { return x + x; } • 5 (number of nodes in AST) print(dbl(inc(), inc()) • 3 (number of leaves in AST) Big ideas 19 Big ideas 20 SemanGcs Example 3 SoluFons StaGc SemanGcs Example 1: Type Checking SoluFons 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 checker)? How do you know? What assumpGons are you making? in the following languages. What is the meaning of the following expressions/ statements in various languages (the syntax might differ from what’s shown).

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