0% found this document useful (0 votes)
10 views9 pages

Big Ideas 4up

The document discusses various aspects of programming languages (PLs), including their definitions, purposes, and the reasons for their creation. It highlights the differences between general-purpose and domain-specific PLs, as well as the importance of syntax, semantics, and pragmatics in programming. Additionally, it touches on programming paradigms and the significance of metaprogramming in language implementation.

Uploaded by

GERRY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Big Ideas 4up

The document discusses various aspects of programming languages (PLs), including their definitions, purposes, and the reasons for their creation. It highlights the differences between general-purpose and domain-specific PLs, as well as the importance of syntax, semantics, and pragmatics in programming. Additionally, it touches on programming paradigms and the significance of metaprogramming in language implementation.

Uploaded by

GERRY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Discussion: Programming Languages

Big Ideas for CS 251 Your experience:


Theory of Programming Languages • What PLs have you used?
Principles of Programming Languages • Which PLs/PL features do you like/dislike. Why?

More generally:
• What is a PL?
• Why are new PLs created?
CS251 Programming Languages – What are they used for?
Spring 2017, Lyn Turbak
– Why are there so many?
Department of Computer Science • Why are certain PLs popular?
Wellesley College • What goes into the design of a PL?

1-2

PL is my passion! General Purpose PLs


• First PL project in 1982 as intern


at Xerox PARC

Created visual PL for 1986 MIT


Java Python Perl
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
1-3 1-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,
we construct a sequence of instrucEons (this
Matlab
LaTeX is a ``program'') and present this sequence to
IDL the machine.
Swift PostScript – Laurence Atkinson, Pascal Programming

1-5 1-6

Programming Languages: LinguisEc View Religious Views


The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offense. – Edsger Dijkstra
A computer language … is a novel formal
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
mentally muElated beyond hope of regeneraEon. – Edsger Dijstra
methodology, not just a way to get a computer
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

1-7 1-8
Programming Language EssenEals PL Parts
Syntax: form of a PL
• What a P in a given L look like as symbols?
• Concrete syntax vs abstract syntax trees (ASTs)

PrimiEves Semantics: meaning of a PL


• Static Semantics: What can we tell about P before running it?

Means of CombinaEon – Scope rules: to which declaration does a variable reference refer?
– Type rules: which programs are well-typed (and therefore legal)?
• Dynamic Semantics: What is the behavior of P? What actions does it
Means of AbstracEon perform? What values does it produce?
– Evaluation rules: what is the result or effect of evaluating each language
fragment and how are these composed?
Think of the languages you know. What means of abstracEon do they have?
Pragmatics: implementation of a PL (and PL environment)
• How can we evaluate programs in the language on a computer?
1-9 • How can we optimize the performance of program execution? 1-10

Syntax (Form) vs. Semantics (Meaning) Concrete Syntax: Absolute Value FuncEon
in Natural Language Logo: to abs :n ifelse :n < 0 [output (0 - :n)] [output :n] end
Javascript: function abs (n) {if (n < 0) return -n; else return n;}
Furiously sleep ideas green colorless. Java: public static int abs (int n) {if (n < 0) return -n; else return n;}
Python: App Inventor:
Colorless green ideas sleep furiously. def abs(n):
if n < 0:
return -n
Little white rabbits sleep soundly. else:
return n
Scheme: (define abs (lambda (n) (if (< n 0) (- n) n)))
PostScript: /abs {dup 0 lt {0 swap sub} if} def

1-11 1-12
Abstract Syntax Tree (AST): This AST abstracts over the Dynamic SemanEcs Example 1
concrete syntax for the Logo,
Absolute Value FuncEon JavaScript, and Python
definiEons. The other definiEons What is the meaning of the following expression?
funcEonDeclaraEon would have different ASTs.
me body
onNa
funcD params
abs condiEonalStatement (1 + 11) * 10
n
test
then

relaEonalOperaEon return return


value value
rand1
lessThan varref intlit arithmeEcOperaEon varref
name
rand1 name
n 0 n
subtract intlit varref
value name
0 n 1-13 1-14

Dynamic SemanEcs Example 2 Dynamic SemanEcs Example 3


Suppose a is an array (or list) containing the three integer values 10, 20, and 30
What is printed by the following program? in the following languages. What is the meaning of the following expressions/
statements in various languages (the syntax might differ from what’s shown).

a = 1; a[1] a[3] a[2] = "foo" a[3] = 17

b = a + 20; Java
C
print(b);
Python
a = 300 JavaScript
print(b); Pascal
count = 0; App Inventor

fun inc() { count = count + 1; return count; }


fun dbl(ignore, x) { return x + x; }
print(dbl(inc(), inc())

1-15 1-16
StaEc SemanEcs Example 1 Static Semantics Example 2: Detecting Loops
Which of the following Java examples is well-typed (i.e., passes the type checker)? Which of these following Python programs has inputs
How do you know? What assumpEons are you making? for which it loops forever?
A 2 * (3 + 4) F if (a) { G public boolean f(int i, boolean b) { A def f(x):
c = a + b; return b && (i > 0);
B 2 < (3 + 4) } else { } return x+1
c = a * b;
C 2 < True } H public int g(int i, boolean b) {
B def g(x): C def g2(x): G def k(x):
return i * (b ? 1 : -1);
}
while True: return g2(x) while x != 1:
D if (a < b) { pass
c = a + b;
if (x % 2) == 0:
I public int p(int w) { return x x = x/2
} else {
c = a * b; if (w > 0) { return 2*w; } else:
} } x = 3*x + 1
E def h(x): F def h2(x): return 1
J public int q(int x) { return x > 0; } while x > 0: if x <= 0:
E if (a < b) {
x = x+1 return x
c = a + b;
} else { K public int r(int y) { return g(y, y>0); } return x else:
c = a > b; return h(x+1)
} L public boolean s(int z) { return f(z); }
1-17 2-18

Static Semantics and Uncomputability The Church-Turing Thesis


It is generally impossible to answer any interesEng quesEon about and Turing-Completeness
staEc program analysis!

This is a consequence of Rice’s Theorem (see CS235). • Church-Turing Thesis: Computability is the common spirit embodied by
this collecEon of formalisms.

For example, will this program ever: • 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
• halt on certain inputs proved.
• encounter an array index out of bounds error? • Because of their similarity to later computer hardware, Turing machines
• throw a NullPointerException? (CS235) have become the gold standard for effecEvely computable.
• access a given object again? • We ll see in CS251 that Church’s lambda-calculus formalism is the
• send sensitive information over the network? foundaEon of modern programming languages.
• divide by 0? • A consequence: programming languages all have the same
• run out of memory, starting with a given amount available? computaEonal power in term of what they can express. All such
• try to treat an integer as an array? languages are said to be Turing-complete.
2-19 2-20
Pragmatics: Raffle App In App Inventor
Expressiveness and Power hIp://ai2.appinventor.mit.edu

• About: Designer Window Blocks Editor


– ease
– elegance
– clarity
– modularity
– abstracEon
– ...
• Not about: computability To enter the raffle, text me now with
• Different problems, different languages an empty message: 339-225-0287
– Facebook or web browser in assembly language?
How hard is this to do in more tradiEonal
development environments for Android/
iOS?
2-21
22

Pragmatics: Metaprogramming Metaprogramming: InterpretaEon


PLs are implemented in terms of metaprogams = programs that
manipulate other programs.
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. Program in Interpreter Machine M
• Transla(on (compila(on): translate a program P in a source language S to a language L for language L
program P’ in a target language T using a translator wriIen in
implementaEon language I.
on machine M
• Embedding: express program P in source language S in terms of data
structures and funcEons in implementaEon language I.

1-23 1-24
Metaprogramming: TranslaEon Metaprogramming: Embedding

Program in
Program in
language A A to B translator
language B
Program in Interpreter Machine M
language A for language B
embedded in on machine M
language B
Interpreter
Machine M
for language B
on machine M 1-25 1-26

Metaprogramming: Programming Language Layers


Metaprogramming: Bootstrapping Puzzles
How can we write a Java-to-x86 compiler in Java?

kernel

primiEve
values/datatypes

syntacEc sugar

system libraries

We’ll learn how to


user libraries
understand such puzzles!
1-27 1-28
PL Dimensions Programming Paradigms
PLs differ based on decisions language designers make in many dimensions. E.g.:
• Impera(ve (e.g. C, Python): ComputaEon is step-by-step execuEon on a
• First-class values: what values can be named, passed as arguments to
funcEons, returned as values from funcEons, stored in data structures. stateful abstract machine involving memory slots and mutable data
Which of these are first-class in your favorite PL: arrays, funcEons, variables? structures.

• Naming: Do variables/parameters name expressions, the values resulEng • Func(onal, func(on-oriented (e.g Racket, ML, Haskell): ComputaEon is
expressed by composing funcEons that manipulate immutable data.
from evaluaEng expressions, or mutable slots holding the values from
evaluaEng expressions? How are names declared and referenced? What • Object-oriented (e.g. Simula, Smalltalk, Java): ComputaEon is expressed in
determines their scope? terms of stateful objects that communicate by passing messages to one
another.
• State: What is mutable and immutable; i.e., what enEEes in the language
(variables, data structures, objects) can change over Eme. • Logic-oriented (e.g. Prolog): ComputaEon is expressed in terms of declaraEve
relaEonships.
• Control: What constructs are there for control flow in the language, e.g.
condiEonals, loops, non-local exits, excepEon handling, conEnuaEons? Note: In pracEce, most PLs involve mulEple paradigms. E.g.
• Data: What kinds of data structures are supported in the language, including • Python supports funcEonal features (map, filter, list comprehensions) and
products (arrays, tuples, records, dicEonaries), sums (opEons, oneofs, objects
variants), sum-of-products, and objects.
• Racket and ML have imperaEve features.
• Types: Are programs staEcally or dynamically typed? What types are
expressible? 1-29 1-30

Paradigm Example: Quicksort Why? Who? When? Where?


Design and ApplicaEon
void qsort(int a[], int lo, int hi) { quicksort :: Ord a => [a] -> [a]
int h, l, p, t;
quicksort [] = []
quicksort (p:xs) =
if (lo < hi) {
l = lo; (quicksort lesser) • Historical context
h = hi; ++ [p]
p = a[hi]; ++ (quicksort greater) • Motivating applications
where
do { lesser = filter (< p) xs – Lisp: symbolic computation, logic, AI, experimental programming
while ((l < h) && (a[l] <= p))
greater = filter (>= p) xs
l = l+1; – ML: theorem-proving, case analysis, type system
while ((h > l) && (a[h] >= p))
h = h-1; – C: Unix operating system
if (l < h) {
t = a[l]; – Simula: simulation of physical phenomena, operations, objects
a[l] = a[h];
a[h] = t; FuncEonal Style (in Haskell) – Smalltalk: communicating objects, user-programmer,
} pervasiveness
} while (l < h);
• Design goals, implementation constraints
a[hi] = a[l];
a[l] = p; – performance, productivity, reliability, modularity, abstraction,
qsort( a, lo, l-1 );
ImperaEve Style extensibility, strong guarantees, …
qsort( a, l+1, hi ); (in C; Java would be similar) • Well-suited to what sorts of problems?
}
1-31 1-32
}
Why study PL?
• Crossroads of CS
Administrivia
• Approach problems as a language designer.
• Schedule, psets, lateness policy, etc.:
– "A good programming language is a conceptual universe for thinking
about programming"
see http://cs.wellesley.edu/~cs251/
-- Alan Perlis • PS0 (introductions) will be posted this afternoon;
– Evaluate, compare, and choose languages due tomorrow
– Become beIer at learning new languages
– become a beIer problem-solver
• PS1 will be posted tomorrow; due next Friday
– view API design as language design • install Dr. Racket for tomorrow
• Ask:
• visit me in office hours!
– Why are PLs are the way they are?
– How could they (or couldn't they) be beIer?
– What is the cost-convenience trade-off for feature X?
1-33 1-34

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy