Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

Similar documents
Programming Languages

CSE 307: Principles of Programming Languages

CSCI 3136 Principles of Programming Languages

Lecture 1: Introduction

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

What is a programming language?

CSE 130 Programming Language Principles & Paradigms

1/20/2016 INTRODUCTION

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

CSC Software II: Principles of Programming Languages

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Functional Programming

Semester Review. CSC 301, Fall 2015

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

1.1 WHAT IS A PROGRAMMING LANGUAGE?

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Image credits:

Fundamentals of Programming Languages

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Fall 2012 Q530. Programming for Cognitive Science

Evolution of the Major Programming Languages

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Programming Language Pragmatics

02-201: Programming for Scientists

Chapter 13: Program Development and Programming Languages

Lesson 06: Basics of Software Development (W02D2

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

McGraw-Hill The McGraw-Hill Companies, Inc.,

CS 253: Intro to Systems Programming

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

USE OF PYTHON AS A SATELLITE OPERATIONS AND TESTING AUTOMATION LANGUAGE

Programming Languages

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Chapter 6: Programming Languages

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

CSCI E 98: Managed Environments for the Execution of Programs

CS 106 Introduction to Computer Science I

Datavetenskapligt Program (kandidat) Computer Science Programme (master)

THE ROLE OF PROGRAMMING PARADIGMS IN THE FIRST PROGRAMMING COURSES. 1. Introduction

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Welcome to Introduction to Computers and Programming Course using Python

Programming Languages

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Object-Oriented Software Specification in Programming Language Design and Implementation

COS 301 Programming Languages

Chapter 15 Functional Programming Languages

Chapter 13: Program Development and Programming Languages

Semantic Analysis: Types and Type Checking

Structure of Presentation. The Role of Programming in Informatics Curricula. Concepts of Informatics 2. Concepts of Informatics 1

CSCE 314 Programming Languages

Moving from CS 61A Scheme to CS 61B Java

Programming Language Concepts for Software Developers

CS 6371: Advanced Programming Languages

Web Development Frameworks

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

02 B The Java Virtual Machine

Introduction to Python

Chapter 12 Programming Concepts and Languages

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

Python Programming: An Introduction to Computer Science

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction

Compiler I: Syntax Analysis Human Thought

Compiler Construction

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Levels of Programming Languages. Gerald Penn CSC 324

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

White Paper: 5GL RAD Development

Asogwa Tochukwu Chijindu Department of Computer Engineering, Enugu State University of Science and Technology(ESUT), Enugu, Nigeria.

Python Programming: An Introduction to Computer Science

1. Overview of the Java Language

Using EDA Databases: Milkyway & OpenAccess

ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Principles of Software Construction: Objects, Design, and Concurrency. Course Introduction. toad. toad Fall School of Computer Science

Language Processing Systems

9/11/15. What is Programming? CSCI 209: Software Development. Discussion: What Is Good Software? Characteristics of Good Software?

Reusable Knowledge-based Components for Building Software. Applications: A Knowledge Modelling Approach

Computer Science. Requirements for the Major (updated 11/13/03)

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

DEGREE PLAN INSTRUCTIONS FOR COMPUTER ENGINEERING

2. Advance Certificate Course in Information Technology

CS 40 Computing for the Web

Compiler and Language Processing Tools

An Easier Way for Cross-Platform Data Acquisition Application Development

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Complexities of Simulating a Hybrid Agent-Landscape Model Using Multi-Formalism

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

CPSC/ECE 3520: Programming Systems Summer Session II 2016 Extended Syllabus

Transcription:

Course Goal CMSC 330: Organization of Programming Languages Introduction Instructors: Michael Hicks and Anwar Mamat Learn how programming languages work Broaden your language horizons Different programming languages Different language features and tradeoffs! Useful programming patterns Study how languages are described / specified Mathematical formalisms Study how languages are implemented What really happens when I write x.foo( )? CMSC 330 1 2 All Languages Are (Kind of) Equivalent A language is Turing complete if it can compute any function computable by a Turing Machine Essentially all general-purpose programming languages are Turing complete I.e., any program can be written in any programming language Studying Programming Languages Helps you to choose between languages Programming is a human activity! Features of a language make it easier or harder to program for a specific application Using the right programming language for a problem may make programming! Easier, faster, less error-prone Therefore this course is useless?! Learn only 1 programming language, always use it 3 4

Studying Programming Languages Become better at learning new languages A language not only allows you to express an idea, it also shapes how you think when conceiving it! There are some fundamental computational paradigms underlying language designs that take getting used to You may need to learn a new (or old) language! Paradigms and fads change quickly in CS! Also, may need to support or extend legacy systems Why Study Programming Languages? To make you better at learning new languages You may need to add code to a legacy system! E.g., FORTRAN (1954), COBOL (1959), You may need to write code in a new language! Your boss says, From now on, all software will be written in {C++/Java/C#/Python } You may think Java is the ultimate language! But if you are still programming or managing programmers in 20 years, they probably won t be programming in Java! 5 6 Studying Programming Languages Improve your understanding of languages you are already familiar with Many design patterns in Java are functional programming techniques Understanding what a language is good for will help you know when it is appropriate to use The deeper your understanding of a language, the better you will be at using it appropriately Course Subgoals Learn some fundamental programminglanguage concepts Regular expressions Automata theory Context free grammars Parallelism & synchronization Improve programming skills Practice learning new programming languages Learn how to program in a new style 7 8

Syllabus Scripting languages (Ruby) Regular expressions & finite automata Context-free grammars & parsing Functional programming (OCaml) Concurrency & synchronization Environments, scoping, type systems Logic programming (Prolog) Comparing language styles; other topics Calendar / Course Overview Tests 4 quizzes, 2 midterms, final exam Projects Project 1-2 Ruby Project 3-4 OCaml Project 5 Multithreading Project 6 Prolog Meet your professor! 1% extra credit : come to chat with your professor during office hours or at a mutually agreed-upon time Conversation need not be long, or technical but we would like to get to know you! 9 10 Project Grading Projects will be graded using the CS submit server Develop programs on your own machine Generally results will be identical on dept machines Your responsibility to ensure programs run correctly on the grace cluster Software versions Ruby 1.9.3 OCaml 4.0.1 SWI-Prolog 6.6.1 Rules and Reminders Use lecture notes as your text Supplement with readings, Internet You will be responsible for everything in the notes, even if it is not directly covered in class! Keep ahead of your work Get help as soon as you need it! Office hours, Piazza (email as a last resort) Don t disturb other students in class Keep cell phones quiet No laptops / tablets in class! Except for taking notes (please sit in back of class) 11 12

Academic Integrity All written work (including projects) must be done on your own Do not copy code from other students Do not copy code from the web Do not post your code on the web We re using Moss; cheaters will be caught Work together on high-level project questions Do not look at/describe another student s code If unsure, ask an instructor! Work together on practice exam questions Changing Language Goals 1950s-60s Compile programs to execute efficiently Language features based on hardware concepts! Integers, reals, goto statements Programmers cheap; machines expensive! Computation was the primary constrained resource! Programs had to be efficient because machines weren t Note: this still happens today, just not as pervasively 13 14 Changing Language Goals Today Language features based on design concepts! Encapsulation, records, inheritance, functionality, assertions Machines cheap; programmers expensive! Scripting languages are slow(er), but run on fast machines! They ve become very popular because they ease the programming process The constrained resource changes frequently! Communication, effort, power, privacy,! Future systems and developers will have to be nimble Language Attributes to Consider Syntax What a program looks like Semantics What a program means (mathematically) Implementation How a program executes (on a real machine) 15 16

Imperative Languages Also called procedural or von Neumann Building blocks are procedures and statements Programs that write to memory are the norm int x = 0; while (x < y) x = x + 1; FORTRAN (1954) Pascal (1970) C (1971) Functional Languages Also called applicative languages Less explicit map to underlying memory Functions are higher-order let rec map f = function [] -> [] x::l -> (f x)::(map f l) LISP (1958) ML (1973) Scheme (1975) Haskell (1987) OCaml (1987) 17 18 OCaml A mostly-functional language Has objects, but won t discuss (much) Developed in 1987 at INRIA in France Dialect of ML (1973) Natural support for pattern matching Generalizes switch/if-then-else very elegant Has full featured module system Much richer than interfaces in Java or headers in C Includes type inference Ensures compile-time type safety, no annotations A Small OCaml Example intro.ml: $ ocaml let greet s = List.iter (fun x -> print_string s) [ hello ; s; "!\n ] Objective Caml version 3.12.1 # #use "intro.ml";; val greet : string -> unit = <fun> # greet "world";; Hello, world! - : unit = () 19 20

Logic-Programming Languages Also called rule-based or constraint-based Program rules constrain possible results Evaluation = constraint satisfaction = search A :- B If B holds, then A holds ( B implies A )! append([], L2, L2).! append([x Xs],Ys,[X Zs]) :- append(xs,ys,zs). PROLOG (1970) Datalog (1977) Various expert systems 21 Prolog A logic programming language 1972, University of Aix-Marseille Original goal: Natural language processing Rule based Rules resemble pattern matching and recursive functions in Ocaml, but more general Execution = search Rules specify relationships among data! Lists, records, atoms, integers, etc. Programs are queries over these relationships! The query will fill in the blanks CMSC 330 - Spring 2011 22 A Small Prolog Example /* A small Prolog program */ female(alice). male(bob). male(charlie). father(bob, charlie). mother(alice, charlie). % X is a son of Y son(x, Y) :- father(y, X), male(x). son(x, Y) :- mother(y, X), male(x). Query?- son(x,y). X = charlie, Y = bob; X = charlie, Y = alice. Multiple answers Lowercase logically terminates Program consists of facts and rules Uppercase denotes variables User types ; to request additional answer User types return to complete request CMSC 330 - Spring 2011 23 Object-Oriented Languages Programs are built from objects Objects combine functions and data! Often into classes which can inherit Base may be either imperative or functional class C { int x; int getx() {return x;} } class D extends C { } Smalltalk (1969) C++ (1986) OCaml (1987) Ruby (1993) Java (1995) 24

Scripting Languages Rapid prototyping languages for common tasks Traditionally: text processing and system interaction Scripting is a broad genre of languages Base may be imperative, functional, OO Increasing use due to higher-layer abstractions Not just for text processing anymore sh (1971) perl (1987) Python (1991) Ruby (1993) #!/usr/bin/ruby while line = gets do csvs = line.split /,/ if(csvs[0] == 330 ) then... Ruby An imperative, object-oriented scripting language Created in 1993 by Yukihiro Matsumoto (Matz) Ruby is designed to make programmers happy Core of Ruby on Rails web programming framework (a key to its popularity) Similar in flavor to many other scripting languages Much cleaner than perl Full object-orientation (even primitives are objects!) 25 26 A Small Ruby Example intro.rb: def greet(s) 3.times { print Hello, } print #{s}!\n end % irb # you ll usually use ruby instead irb(main):001:0> require "intro.rb" => true irb(main):002:0> greet("world") Hello, Hello, Hello, world! => nil Concurrent / Parallel Languages Traditional languages had one thread of control Processor executes one instruction at a time Newer languages support many threads Thread execution conceptually independent Means to create and communicate among threads Concurrency may help/harm Readability, performance, expressiveness Many examples Erlang, Cilk, Conc. Haskell, Fortress, UPC C/C++, Java, Ruby, OCaml, Python, 27 28

Other Languages There are lots of other languages w/ various features COBOL (1959) Business applications! Imperative, rich file structure BASIC (1964) MS Visual Basic! Originally designed for simplicity (as the name implies)! Now it is object-oriented and event-driven, widely used for UIs Logo (1968) Introduction to programming Forth (1969) Mac Open Firmware! Extremely simple stack-based language for PDP-8 Ada (1979) The DoD language! Real-time Postscript (1982) Printers- Based on Forth Program Execution Suppose we have a program P written in a high-level language (i.e., not machine code) There are two main ways to run P 1. Compilation 2. Interpretation 29 30 Compilation Interpretation def greet(s) print("hello, ) print(s) print("!\n ) end 11230452 23230456 01200312 def greet(s) print("hello, ) print(s) print("!\n ) end Hello, world! world world Hello, world! Source program translated ( compiled ) to another language Traditionally: directly executable machine code Generating code from a higher level interface is also common (e.g., JSON, RPC IDL) Interpreter executes each instruction in source program one step at a time No separate executable 31 32

Architecture of Compilers, Interpreters Front Ends and Back Ends Source Parser Static Analyzer Front End Intermediate Representation Compiler / Interpreter Back End Front ends handle syntactic analysis Parser converts source code into intermediate format ( parse tree ) reflecting program structure Static analyzer checks parse tree for errors (e.g. types), may also modify it What goes into static analyzer is languagedependent! Back ends handle semantics Compiler: back end ( code generator ) translates intermediate representation into object language Interpreter: back end executes intermediate representation directly 33 34 Compiler or Intepreter? gcc Compiler C code translated to object code, executed directly on hardware (as a separate step) javac Compiler Java source code translated to Java byte code java Interpreter Java byte code executed by virtual machine sh/csh/tcsh/bash Interpreter commands executed by shell program Compilers vs. Interpreters Compilers Generated code more efficient Heavy Interpreters Great for debugging Slow In practice General-purpose programming languages (e.g. C, Java) are often compiled, although debuggers provide interpreter support Scripting languages and other special-purpose languages are interpreted, even if general purpose 35 36

Formal (Mathematical) Semantics What do my programs mean? let rec fact n = if n = 0 then 1 else n * (fact n-1) let fact n = let rec aux i j = if i = 0 then j else aux (i-1) (j*i) in aux n 1 Both OCaml functions implement the factorial function. How do I know this? Can I prove it? Key ingredient: a mathematical way of specifying what programs do, i.e., their semantics Doing so depends on the semantics of the language Semantic styles Textual language definitions are often incomplete and ambiguous A formal semantics is basically a mathematical definition of what programs do. Two flavors: Denotational semantics (compiler/translator)! Meaning defined in terms of another language (incl. math)! If we know what C means, then we can define Ruby by translation to C Operational semantics (interpreter)! Meaning defined as rules that simulate program execution! Show what Ruby programs do directly, using an abstract machine, more high-level than real hardware 37 38 Attributes of a Good Language Cost of use Program execution (run time), program translation, program creation, and program maintenance Portability of programs Develop on one computer system, run on another Programming environment External support for the language Libraries, documentation, community, IDEs, Attributes of a Good Language Clarity, simplicity, and unity Provides both a framework for thinking about algorithms and a means of expressing those algorithms Orthogonality Every combination of features is meaningful Features work independently Naturalness for the application Program structure reflects the logical structure of algorithm 39 40

Attributes of a Good Language What Programmers Want In a PL Support for abstraction Hide details where you don t need them Program data reflects the problem you re solving Security & safety Should be very difficult to write unsafe programs Ease of program verification Does a program correctly perform its required function? 41 Meyerovitch & Rabin, Empirical analysis of programming language adoption, OOPSLA 13 42 Summary Many types of programming languages Imperative, functional, logical, OO, scripting, Many programming language attributes Clear, natural, low cost, verifiable, Programming language implementation Compiled, interpreted Programming language semantics Proving your program operates correctly 43