CS 655: Programming Languages Scheming Schemers, Mocking Mockingbirds, and Objecting Objectively Lecture 1:Wherefore CS655? The use of <???> cripples the mind; its teaching should, therefore, be regarded as a criminal offence. Edsger W.Dijkstra, 1975 CS655: Programming Languages David Evans University of Virginia http://www.cs.virginia.edu/~evans Computer Science Menu • What is Computer Science? • Goals for the Course • Programming Languages – Design Tradeoffs Send registration email by Sunday 18 Jan 2001 CS 655: Lecture 1 2 What is Computer Science? 18 Jan 2001 CS 655: Lecture 1 3 Let AB and CD be the two given numbers not relatively prime. It is required to find the greatest common measure of AB and CD. If now CD measures AB, since it also measures itself, then CD is a common measure of CD and AB. And it is manifest that it is also the greatest, for no greater number than CD measures CD. But, if CD does not measure AB, then, when the less of the numbers AB and CD being continually subtracted from the greater, some number is left which measures the one before it. 18 Jan 2001 CS 655: Lecture 1 4 For a unit is not left, otherwise AB and CD would be relatively prime, which is contrary to the hypothesis. Therefore some number is left which measures the one before it. Now let CD, measuring BE, leave EA less than itself, let EA, measuring DF, leave FC less than itself, and let CF measure AE. Since then, CF measures AE, and AE measures DF, therefore CF also measures DF. But it measures itself, therefore it also measures the whole CD. But CD measures BE, therefore CF also measures BE. And it also measures EA, therefore it measures the whole BA. But it also measures CD, therefore CF measures AB and CD. Therefore CF is a common measure of AB and CD. I say next that it is also the greatest. If CF is not the greatest common measure of AB and CD, then some number G, which is greater than CF, measures the numbers AB and CD. Now, since G measures CD, and CD measures BE, therefore G also measures BE. But it also measures the whole BA, therefore it measures the remainder AE. But AE measures DF, therefore G also measures DF. And it measures the whole DC, therefore it also measures the remainder CF, that is, the greater measures the less, which is impossible. Therefore no number which is greater than CF measures the numbers AB and CD. Therefore CF is the greatest common measure of AB and CD. Euclid’s Elements, Book VII, Proposition 2 (300BC) 18 Jan 2001 CS 655: Lecture 1 5 By the word operation, we mean any process which alters the mutual relation of two or more things, be this relation of what kind it may. This is the most general definition, and would include all subjects in the universe. Again, it might act upon other things besides number, were objects found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine... Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent. Ada, Countess of Lovelace, around 1830 18 Jan 2001 CS 655: Lecture 1 6 What is the difference between Euclid and Ada? “It depends on what your definition of ‘is’ is.” Bill Gates (speaking at Microsoft’s anti-trust trial) 18 Jan 2001 CS 655: Lecture 1 7 Geometry vs. Computer Science • Geometry (mathematics) is about declarative knowledge: “what is” If now CD measures AB, since it also measures itself, then CD is a common measure of CD and AB • Computer Science is about imperative knowledge: “how to” Computer Science has nothing to do with beige (or translucent blue) boxes called “computers” and is not a science. 18 Jan 2001 CS 655: Lecture 1 8 Next: My Goals for the Course 18 Jan 2001 CS 655: Lecture 1 9 Goal #1 Make this the first real Computer Science most of you have taken. 18 Jan 2001 CS 655: Lecture 1 10 Imperative Knowledge • The core of Computer Science is describing and reasoning about computations • This class is about: – Tools for describing computations (programming languages) – Tools for reasoning about those tools (mostly formal semantics) 18 Jan 2001 CS 655: Lecture 1 11 Goal #2 Not waste your time. 18 Jan 2001 CS 655: Lecture 1 12 Graduate Students • Should make research their highest priority (after sleeping, eating, and maintaining sanity and happiness) • Should not spend time on courses except when it: – Makes them better researchers – Is of intrinsic interest and value • Should be mature enough to decide what it is worthwhile to spend time on 18 Jan 2001 CS 655: Lecture 1 13 Hence: • Everything in this class is optional – Except Problem Set 0: Registration Survey • You should not take this course unless you believe most of the material we will cover is either: – Relevant to your research – Intrinsically cool and interesting (Note: all of it is both) 18 Jan 2001 CS 655: Lecture 1 14 Evaluation • I still need to grade you, of course... • To get an A in this course, you need to convince me of your deep understanding of the most important course material. 18 Jan 2001 CS 655: Lecture 1 15 Ways to get an A in CS 655 1. Do well on the assignments or 2. Do well on an oral final exam or 3. Produce a quality research paper on a relevant topic or 4. Demonstrate your understanding through outstanding class contributions 18 Jan 2001 CS 655: Lecture 1 16 Questions Next: Goals 3-8 18 Jan 2001 CS 655: Lecture 1 17 Goal #3 When you need to invent a language (and most of you will at some point in your career) you will design it, not just make it up. 18 Jan 2001 CS 655: Lecture 1 18 What’s the difference? Designed Just Made Up Examples Esperanto, CLU English, C++ Properties Predictable Unpredictable Ways to do something One Many Users ~1M; .5 - 15 ~1B; ~1M Moral? A bigger army beats good design every time But, good designs can influence people with armies 18 Jan 2001 CS 655: Lecture 1 19 Goal #4 When you design your language, you will have sufficient knowledge of other languages not to repeat their mistakes, and solid enough theory background to describe your language well. 18 Jan 2001 CS 655: Lecture 1 20 Goal #5 You will become better at programming and building systems. You will think more clearly and maybe even write better. A language that doesn't affect the way you think about programming, is not worth knowing. Alan Perlis 18 Jan 2001 CS 655: Lecture 1 21 Goal #6 Some of you will do projects that lead to conference papers and influence your theses. All of you will be able to understand nearly all PLDI papers and many POPL papers. 18 Jan 2001 CS 655: Lecture 1 22 Goal #7 Enable at least half of you to understand at 5 least half of R RS Section 7.2 (2½ pages) 18 Jan 2001 CS 655: Lecture 1 23 Goal #8 18 Jan 2001 CS 655: Lecture 1 24 Disclaimer • Sorry, no refunds if not all goals are satisfied. • Tell me your goals on the survey. 18 Jan 2001 CS 655: Lecture 1 25 Questions Next: What is a Programming Language? 18 Jan 2001 CS 655: Lecture 1 26 What is a language? Webster: A systematic means of communicating ideas or feelings by the use of conventionalized signs, sounds, gestures, or marks having understood meanings. 18 Jan 2001 CS 655: Lecture 1 27 Nerdy Linguist’s Definition A description of pairs (S, M), where S stands for sound, or any kind of surface forms, and M stands for meaning. A theory of language must specify the properties of S and M, and how they are related. 18 Jan 2001 CS 655: Lecture 1 28 Programming Language A language (according to the Nerdy Linguist’s definition) intended to be read and written by humans and processed by machines. Stricter definition add: that has some notion of control flow. 18 Jan 2001 CS 655: Lecture 1 29 Some other definitions • Bruce MacLellan’s definition: A language that is intended for the expression of computer programs and that is capable of expressing any computer program. • Ravi Sethi’s definition: Notations used for specifying, organizing, and reasoning about computations. 18 Jan 2001 CS 655: Lecture 1 30 What makes a PL important? 18 Jan 2001 CS 655: Lecture 1 31 Lots of People Learn It 100 Java HTML 1000 Eiffel Pascal Ada Lisp FORTRAN COBOL Tcl C++ C Basic 10000 No books in print: Algol60, CLU, Simula 100000 Amazon.com sales rank for best-selling book related to language (30 November 1999) 18 Jan 2001 CS 655: Lecture 1 32 You Can Get a Job 1000 HTML Basic Java C++ 100 Pascal FORTRAN No job listings: Algol60, CLU, Simula Tcl Ada COBOL 10 1 Monster.com job listings in Virginia matching language 18 Jan 2001 CS 655: Lecture 1 (30 November 1999) 33 Changes How Programmers Think Influences other Languages • • • • • FORTRAN - use a high level language Algol60 - program in a structured way Simula - use classes CLU - use data abstraction FP - program without state 18 Jan 2001 CS 655: Lecture 1 34 Languages we will focus on • Scheme – Simplest, cleanest, most elegant language I know – Extremely powerful tool for describing computations • CLU – Because I like it, and its my course – Because it has the best support for data abstraction • Java – Because it is popular and modern • Others, possibly including: – Ada, Algol60, Algol68, C, C++, Eiffel, Euclid, FL, ML, Linda, Pascal, Sather, Simula, Tcl 18 Jan 2001 CS 655: Lecture 1 35 Language Design Art and Engineering 18 Jan 2001 CS 655: Lecture 1 36 Language Design as Engineering Safety Performance Java, CLU FORTRAN, BLISS, C Ease of Use BASIC, CLU Ease/size of Implementation Forth, C Orthogonality Safety, Simplicity Algol68 Pascal Simplicity Expressiveness Scheme Common LISP 18 Jan 2001 CS 655: Lecture 1 37 Example: Is assignment an expression? • Wulf (BLISS): Of course, everything is a := if .c >4 then .e else f := 7 • Richie (C): Yes, why not while (x = 0) x++; but not: x = if (a > 3) 4 else 5; • Wirth (Pascal): No, only math-like things are expressions Who’s right? What were their design tradeoffs? 18 Jan 2001 CS 655: Lecture 1 38 C’s main design requirement Memory Space 24K on PDP-11 total. Needed to fit OS, compiler, and leave a little room for user programs. The “good” languages and operating systems of the day (Algol60, Multics) didn’t fit. Note: C++’s main design requirement: be as compatible as possible with C. 18 Jan 2001 CS 655: Lecture 1 39 Language Design as Art • Aesthetics matter • Readability is usually more important than Writability – CLU vs. APL • Intuitive meaning more important than formal semantics – But formal semantics necessary to make sure we agree on intuitive meaning 18 Jan 2001 CS 655: Lecture 1 40 Interaction of Art & Engineering Example: C void test (int x) { while (x = 1) { printf (“I’m an imbecile!”); x = x + 1; } } Art: use = for assignment (not :=) Engineering: make assignments expressions, no Boolean type, weak types, etc. 18 Jan 2001 CS 655: Lecture 1 41 Charge • Think about my definition of Computer Science – Send me a better one if you can • Think about how well the languages you use are designed • Send me your registration survey by Sunday • Next time: Scheme 18 Jan 2001 CS 655: Lecture 1 42