What is programming? Elements of Programming Languages. From machine code to programming languages. What is a programming language?

Similar documents
CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Programming Languages, Summary CSC419; Odelia Schwartz

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

CSCI 3136 Principles of Programming Languages

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Seminar in Programming Languages

Com S 541. Programming Languages I

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

IA010: Principles of Programming Languages

Concepts of Programming Languages

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Programmiersprachen (Programming Languages)

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg

Concepts in Programming Languages

CSc 372 Comparative Programming Languages

COSE212: Programming Languages. Lecture 0 Course Overview

Concepts of Programming Languages

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

CS252 Advanced Programming Language Principles. Prof. Tom Austin San José State University Fall 2013

15-411/ Compiler Design

Compilers Project Proposals

New Programming Paradigms

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

CMSC 330: Organization of Programming Languages

CSE341: Programming Languages Lecture 26 Course Victory Lap. Dan Grossman Spring 2016

Programming Languages 2nd edition Tucker and Noonan"

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Functional Programming Lecture 1: Introduction

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

cmpt 440/821 Advanced Topics in Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Introduction to Computer Science I

Objective: To learn meaning and concepts of programming. Outcome: By the end of this students should be able to describe the meaning of programming

CS 415 Midterm Exam Spring 2002

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

LECTURE 1. Overview and History

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Overview. Elements of Programming Languages. Another example. Consider the humble identity function

Chapter 1. Preliminaries

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

Logic Programming II & Revision

Lecture 6 Introduction to Objects and Classes

Lecture 1: Introduction. 23. August, 2010

Stop coding Pascal. Saturday, April 6, 13

CS 242. Fundamentals. Reading: See last slide

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

CSCI.4430/6969 Programming Languages Lecture Notes

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 3304 Comparative Languages. Lecture 1: Introduction

Programming Language Design and Implementation. Cunning Plan. Your Host For The Semester. Wes Weimer TR 9:30-10:45 MEC 214. Who Are We?

Compiler Construction

Chapter 1. Preliminaries

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Programming (Econometrics)

Formal Systems and their Applications

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

Simply-Typed Lambda Calculus

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Principles of Programming Languages. Lecture Outline

Introduction to the course and basic programming concepts

Programming language design and analysis

SOFTWARE ARCHITECTURE 6. LISP

Functional Programming Principles in Scala. Martin Odersky

Lecture 1: Course Introduction

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

Lecture 13 CIS 341: COMPILERS

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

Programming (ERIM) Lecture 1: Introduction to programming paradigms and typing systems. Tommi Tervonen

Paradigms of computer programming

6. Discuss how producer-consumer problem and Dining philosophers problem are solved using concurrency in ADA. [16]

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

1DL321: Kompilatorteknik I (Compiler Design 1)

Informatica 3 Syntax and Semantics

Introduction to Scientific Computing Languages

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Anders Møller Michael Schwartzbach Erik Ernst Hans Hüttel

Introduction to Scientific Computing Languages

Lecture 1: Course Introduction

CS A331 Programming Language Concepts

Programming Languages FILS Andrei Vasilateanu

CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

COSC 2P90 Programming Languages & Object-Orientation

Programming Paradigms

Comp 333: Concepts of Programming Languages Fall 2016

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

G Programming Languages Spring 2010 Lecture 1. Robert Grimm, New York University

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Programming Languages 1. Introduction. Oscar Nierstrasz

COMPILER DESIGN LECTURE NOTES

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

Functional Programming. Big Picture. Design of Programming Languages

CS558 Programming Languages

Transcription:

What is programming? Elements of Programming Languages Lecture 0: Introduction and Course Outline James Cheney University of Edinburgh September 18, 2017 Computers are deterministic machines, controlled by low-level (usually binary) machine code instructions. Acomputercan [only] do whatever we know how to order it to perform (Ada Lovelace, 1842) Programming is communication: between a person and a machine, to tell the machine what to do between people, to communicate ideas about algorithms and computation From machine code to programming languages What is a programming language? The first programmers wrote all of their code directly in machine instructions ultimately, these are just raw sequences of bits. Such programs are extremely di understand. cult to write, debug or Simple assembly languages were introduced very early (1950 s) as a human-readable notation for machine code FORTRAN (1957) one of the first high-level languages (procedures, loops, etc.) For the purpose of this course, a programming language is a formal, executable language for computations Non-examples: English (not formal) First-order Logic (formal, but not executable in general) HTML4 (formal, executable but not computational) (HTML is in a gray area with JavaScript or HTML5 extensions it is a lot more computational )

Some di erent languages # Python, Haskell, Scala print("hello, world!") // Java public class HelloWorld { public static void main(string[] args) { System.out.println("Hello, World"); } } -- SQL SELECT DISTINCT Hello world AS new_value FROM AnyTableWithOneOrMoreRows WHERE 1 = 1; Why are there so many? Imperative/procedural: FORTRAN, COBOL, Algol, Pascal, C Object-oriented, untyped: Simula, Smalltalk, Python, Ruby, JavaScript Object-oriented, typed: C++, Java, Scala, C# Functional, untyped: LISP, Scheme, Racket Functional, typed: ML, OCaml, Haskell, (Scala), F# Logic/declarative: Prolog, Curry, SQL What do they have in common? What are the di erences? All (formal) languages have a written form: we call this (concrete) syntax All (executable) languages can be implemented on computers: e.g. by a compiler or interpreter All programming languages describe computations: they have some computational meaning, orsemantics In addition, most languages provide abstractions for organizing, decomposing and combining parts of programs to solve larger problems. There are many so-called programming language paradigms : imperative (variables, assignment, if/while/for, procedures) object-oriented (classes, inheritance, interfaces, subtyping) typed (statically, dynamically, strongly, un/uni-typed) functional ( -calculus, pure, lazy) logic/declarative (computation as deduction, query languages)

Languages, paradigms and elements Applicability Agreatdealofe orthasbeenexpendedtryingtofind the best paradigm, with no winner declared so far. In reality, they all have strengths and weaknesses, and almost all languages make compromises or synthesize ideas from several paradigms. This course emphasizes di erent programming language features, orelements Analogy: periodic table of the elements in chemistry Goal: understand the basic components that appear in a variety of languages, and how they combine or react with one another. Major new general-purpose languages come along every decade or so. Hence, few programmers or computer scientists will design a new, widely-used general purpose language, or write a compiler However, domain-specific languages are increasingly used, and the same principles of design apply to them Moreover, understanding the principles of language design can help you become a better programmer Learn new languages / recognize new features faster Understand when and when not to use a given feature Assignments will cover practical aspects of programming languages: interpreters and DSLs/translators Sta Course Administration Lecturer: James Cheney <jcheney@inf.ed.ac.uk>, IF 5.29 O ce hours: Tuesday 11:30-12:30, or by appointment TA: TBA

Format Feedback and Assessment 20 lectures (M/Th 1510 1600) 2 intro/review [non-examinable] 2 guest lectures [non-examinable] 16 core material [examinable] 1two-hourlab session (September 27, 1210 1400) 8one-hourtutorial sessions, startinginweek3(times and groups TBA) All of these activities are part of the course and may cover examinable material, unless explicitly indicated. Coursework: Assignment 1: Lab exercise sheet, available during week 2, due during week 3, worth 0% of final grade Assignment 2: available during week 3, due week 6, worth 0% of final grade. Assignment 3: available during week 6, due week 10, worth 25% of final grade. The first two assignments are marked for formative feedback only, but the third builds on the first two. One (written) exam: worth 75% of final grade. Scala Recommended reading The main language for this course will be Scala Scala o ers an interesting combination of ideas from functional and object-oriented programming styles We will use Scala (and other languages) to illustrate key ideas We will also use Scala for the assignments However, this is not a course on Scala You will be expected to figure out certain things for yourselves (or ask for help) We will not teach every feature of Scala, nor are you expected to learn every dark corner In fact, part of the purpose of the course is to help you recognize such dark corners and avoid them unless you have a good reason... There is no o cial textbook for the course that we will follow exactly However, the following are recommended readings to complement the course material: Practical Foundations for Programming Languages, second edition, (PFPL2), by Robert Harper. Available online from the author s webpage and through the University Library s ebook access. Concepts in Programming Languages (CPL), by John Mitchell. Available through the University Library s ebook access. Slides available on web page, lecture notes available in Piazza (new this year)

Wadler s Law In any language design, the total time spent discussing a feature in this list is proportional to two raised to the power of its position. 0. Semantics 1. Syntax 2. Lexical syntax 3. Lexical syntax of comments Wadler s law is an example of a phenomenon called bike-shedding : the number of people who feel qualified to comment on an issue is inversely proportional to the expertise required to understand it Syntax This course is primarily about language design and semantics. As a foundation for this, we will necessarily spend some time on abstract syntax trees (and programming with them in Scala) We will cover: Name-binding, substitution, static vs. dynamic scope We will not cover: Concrete syntax, lexing, parsing, precedence (but Compiling Techniques does) Interpreters, Compilers and Virtual Machines Semantics Suppose we have a source programming language L S,a target language L T,andanimplementation language L I An interpreter for L S is an L I program that executes L S programs. When both L S and L I are low-level (e.g. L S = JVM, L I = x86), an interpreter for L is called a virtual machine. A translator from L S to L T is an L I program that translates programs in L S to equivalent programs in L T. When L T is low-level, a translator to L T is usually called a compiler. In this course, we will use interpreters to explore di erent language features. How can we understand the meaning of a language/feature, or compare di erent languages/features? Three basic approaches: Operational semantics defines the meaning of a program in terms of rules that explain the step-by-step execution of the program Denotational semantics defines the meaning of a program by interpreting it in a mathematical structure Axiomatic semantics defines the meaning of a program via logical specifications and laws All three have strengths and weaknesses We will focus on operational semantics in this course: it is the most accessible and flexible approach.

The three most important things Data Structures and Abstractions The three most important considerations for programming language design are: (Data) Abstraction (Control) Abstraction (Modular) Abstraction We will investigate di erent language elements that address the need for these abstractions, and how di erent design choices interact. In particular, we will see how types o er a fundamental organizing principle for programming language features. Data structures provide ways of organizing data: option types vs. null values pairs/record types; variant/union types; lists/recursive types; pointers/references Data abstractions make it possible to hide data structure choices: overloading (ad hoc polymorphism) generics (parametric polymorphism) subtyping abstract data types Control Structures and Abstractions Design dimensions and modularity Control structures allow us to express flow of control: goto for/while loops case/switch exceptions Control abstractions make it possible to hide implementation details: procedure call/return function types/higher-order functions continuations Programming in the large requires considering several cross-cutting design dimensions: eager vs. lazy evaluation purity vs. side-e ects static vs. dynamic typing and modularity features modules, namespaces objects, classes, inheritance interfaces, information hiding

The art and science of language design Language design is both an art and a science The most popular languages are often not the ones with the cleanest foundations (and vice versa) This course teaches the science: formalisms and semantics Aesthetics and good design are hard to teach (and hard to assess), but one of the assignments will give you an opportunity to experiment with domain-specific language design Relationship to other courses Course goals By the end of this course, you should be able to: 1 Investigate the design and behaviour of programming languages by studying implementations in an interpreter 2 Employ abstract syntax and inference rules to understand and compare programming language features 3 Design and implement a domain-specific language capturing a problem domain 4 Understand the design space of programming languages, including common elements of current languages and how they are combined to construct language designs 5 Critically evaluate the programming languages in current use, acquire and use language features quickly, recognise problematic programming language features, and avoid their (mis)use. Summary Compiling Techniques covers complementary aspects of PL implementation, such as lexical analysis and parsing. also covers compilation of imperative programs to machine code Introduction to Theoretical Computer Science covers formal models of computation (Turing machines, etc.) as well as some -calculus and type theory In this course, we focus on interpreters, operational semantics, andtypes to understand programming language features. There should be relatively little overlap with CT or ITCS. Today we covered: Background and motivation for the course Course administration Outline of course topics Next time: Concrete and abstract syntax Programming with abstract syntax trees (ASTs)