Programming Languages: Concepts

Similar documents
Concepts in Programming Languages

Coding Tools. (Lectures on High-performance Computing for Economists VI) Jesús Fernández-Villaverde 1 and Pablo Guerrón 2 March 25, 2018

CSCI 334: Principles of Programming Languages. Computer Architecture (a really really fast introduction) Lecture 11: Control Structures II

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

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

Computer Systems Lecture 9

Java and C II. CSE 351 Spring Instructor: Ruth Anderson

Practical Malware Analysis

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Subprograms: Local Variables

Programming. translate our algorithm into set of instructions machine can execute

How Software Executes

SOEN228, Winter Revision 1.2 Date: October 25,

Topic 9: Type Checking

Topic 9: Type Checking

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Software II: Principles of Programming Languages. Why Expressions?

Program Exploitation Intro

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Principles of Programming Languages. Lecture Outline

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut

CS61 Section Solutions 3

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Chapter 5. Names, Bindings, and Scopes

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

16.317: Microprocessor Systems Design I Fall 2014

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Memory Management. Kevin Webb Swarthmore College February 27, 2018

What is a programming language?

CSE373: Data Structure & Algorithms Lecture 23: Programming Languages. Aaron Bauer Winter 2014

Programming Languages, Summary CSC419; Odelia Schwartz

Chapter 7. Expressions and Assignment Statements ISBN

CS558 Programming Languages

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

Chapter 7. Expressions and Assignment Statements

CSC 8400: Computer Systems. Machine-Level Representation of Programs

4. Jump to *RA 4. StackGuard 5. Execute code 5. Instruction Set Randomization 6. Make system call 6. System call Randomization

CPS104 Recitation: Assembly Programming

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Chapter 11 Introduction to Programming in C


Lab 3. The Art of Assembly Language (II)

Static Typing or Dynamic Typing: A Real Issue or a Simple Case of Tribalism

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

Q1: Multiple choice / 20 Q2: Data transfers and memory addressing

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

Subprograms: Arguments

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

6 Character Classification and Utilities Module (chars.hhf)

IA010: Principles of Programming Languages

15-213/18-243, Spring 2011 Exam 1

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

(the bubble footer is automatically inserted into this space)

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

Programming Languages FILS Andrei Vasilateanu

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Overview of Compiler. A. Introduction

Welcome to Python! If you re the type of person who wants to know

Assembly Language: Function Calls" Goals of this Lecture"

Type Checking and Type Equality

Compilers Crash Course

Programming. leads to programming languages. leads to operating systems

CS377P Programming for Performance Leveraging the Compiler for Performance

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut

Compiler Construction D7011E

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

Towards the Hardware"

COMPUTER ENGINEERING DEPARTMENT

Assembly Language: Function Calls" Goals of this Lecture"

Chapter 7. Expressions and Assignment Statements

Software Development. Integrated Software Environment

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

Roadmap: Security in the software lifecycle. Memory corruption vulnerabilities

Why are there so many programming languages?

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

x86 assembly CS449 Fall 2017

Introducing Computer Programming

CSCI 3136 Principles of Programming Languages

How Software Executes

Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

Secure Programming Lecture 3: Memory Corruption I (Stack Overflows)

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

Computer Science Final Examination Wednesday December 13 th 2006

Programming Paradigms

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Types. What is a type?

16.317: Microprocessor Systems Design I Fall 2015

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

T Jarkko Turkulainen, F-Secure Corporation

12.1 Chapter Overview Tables Function Computation via Table Look-up. Calculation Via Table Lookups

New Programming Paradigms

Assembly Language: Function Calls

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

EECE.3170: Microprocessor Systems Design I Summer 2017

Transcription:

Programming Languages: Concepts (Lectures on High-performance Computing for Economists IV) Jesús Fernández-Villaverde 1 and Pablo Guerrón 2 February 18, 2018 1 University of Pennsylvania 2 Boston College

Introduction

Motivation Since the invention of Fortran in 1954-1957 to substitute assembly language, hundreds of programming languages have appeared. Some more successful than others, some more useful than others. Moreover, languages evolve over time (different version of Fortran). Different languages are oriented toward certain goals and have different approaches. 1

2

Some references Programming Language Pragmatics (4th Edition), by Michael L. Scott. Essentials of Programming Languages (3rd Edition), by Daniel P. Friedman and Mitchell Wand. Concepts of Programming Languages (11th Edition), by Robert W. Sebestat. http://hyperpolyglot.org/ 3

The basic questions Which programming language to learn? Which programming language to use in this project? Do I need to learn a new language? 4

Which programming language? I Likely to be a large investment. Also, you will probably want to be familiar at least with a couple of them (good mental flexibility) plus L A TEX. Alan Perlis A language that doesn t affect the way you think about programming is not worth knowing. There is a good chance you will need to recycle yourself over your career. 5

Which programming language? II Typical problems in economics can be: 1. CPU-intensive. 2. Memory-intensive. Imply different emphasis. Because of time constraints, we will not discuss memory-intensive tools such as Hadoop and Spark. 6

Classification

Classification There is no best solution. But there are some good tips. We can classify programming languages according to different criteria. We will pick several criteria that are relevant for economists: 1. Level. 2. Domain. 3. Execution. 4. Type. 5. Paradigm 7

Level Levels: 1. machine code. 2. Low level: assembly language like NASM (http://www.nasm.us/), GAS, or HLA (The Art of Assembly Language (2nd Edition), by Randall Hyde). 3. High level: like C/C++, Julia,... You can actually mix different levels (C). Portability. You are unlikely to see low level programming unless you get into the absolute frontier of performance (for instance, with extremely aggressive parallelization). 8

Fibonacci number Machine code: 8B542408 83FA0077 06B80000 0000C383 FA027706 B8010000 00C353BB 01000000 B9010000 008D0419 83FA0376 078BD98B C84AEBF1 5BC3 Assembler: ib: mov edx, [esp+8] cmp edx, 0 ja @f mov eax, 0 ret @@: cmp edx, 2 ja @f mov eax, 1 ret @@: push ebx mov ebx, 1 mov ecx, 1 @@: lea eax, [ebx+ecx] cmp edx, 3 jbe @f mov ebx, ecx mov ecx, eax dec edx jmp @b @@: pop ebx ret C++: int fibonacci(const int x) { if (x==0) return(0); if (x==1) return(1); return (fibonacci(x-1))+fibonacci(x-2);} 9

10

Domain Domain: 1. General-purpose programming languages (GPL), such as Fortran, C/C++, Python,... 2. Domain specific language (DSL) such as Julia, R, Matlab, Mathematica,... Advantages/disadvantages: 1. GPL are more powerful, usually faster to run. 2. DSL are easier to learn, faster to code, built-in functions and procedures. 11

Execution I Three basic modes to run code: 1. Interpreted: Python, R, Matlab, Mathematica. 2. Compiled: Fortran, C/C++. 3. JIT (Just-in-Time) compilation: Julia. Interpreted languages can we used with: 1. A command line in a REPL (Read eval print loop). 2. A script file. Many DSL are interpreted, but this is neither necessary nor sufficient. Advantages/disadvantages: similar to GPL versus DSL. Interpreted and JIT programs are easier to move across platforms. 12

Execution II In reality, things are somewhat messier. Some languages are explicitly designed with an interpreter and a compiler (Haksell, Scala, F#). Compiled programs can be extended with third-party interpreters (CINT and Cling for C/C++). Often, interpreted programs can be compiled with an auxiliary tool (Matlab, Mathematica,...). Interpreted programs can also be compiled into byte code (R, languages that run on the JVM -by design or by a third party compiler). We can mix interpretation/compilation with libraries. 13

Types I Type strength: 1. Strong: type enforced. 2. Weak: type is tried to be adapted. Type expression: 1. Manifest: explicit type. 2. Inferred: implicit. Type checking: 1. Static: type checking is performed during compile-time. 2. Dynamic: type checking is performed during run-time. Type safety: 1. Safe: error message. 2. Unsafe: no error. 14

Types II Advantages of strong/manifest/static/safe type: 1. Easier to find programming mistakes ADA, for critical real-time applications, is strongly typed. 2. Easier to read. 3. Easier to optimize for compilers. 4. Faster runtime not all values need to carry a dynamic type. Disadvantages: 1. Harder to code. 2. Harder to learn. 3. Harder to prototype. 15

Types III You implement strong/manifest/static/safe typing in dynamically typed languages. You can define variables explicitly. For example, in Julia: a::int = 10 It often improve performance speed and safety. You can introduce checks: a = "This is a string" if typeof(a) == String println(a) else println("error") end 16

17

18

Language popularity I C family (a subset of the ALGOL family), also known as curly-brackets languages : 1. C, C++, C#: 20.40%: 3 out of top 5. 2. Java, C, C++, C#, JavaScript, PHP, Perl: 47.78%: 7 out of top 10. Python: position 4, 4.68%. R: position 8, 2.55%. Matlab: position 15, 1.83%. Fortran: position 33, 0.43%. Julia: position 47, 0.23%. 19

Language popularity II High-performance and scientific computing is a small area within the programming community. Thus, you need to read the previous numbers carefully. For example: 1. You will most likely never use JavaScript or PHP (at least while wearing with your economist hat) or deal with an embedded system. 2. C# and Swift are cousins of C focused on industry applications not very relevant for you. 3. Java (usually) pays a speed penalty. 4. Fortran is still used in some circles in high-performance programming, but most programmers will never bump into anyone who uses Fortran. 20

Multiprogramming Attractive approach in many situations. Best IDEs can easily link files from different languages. Easier examples: 1. Cpp.jl and PyCall in Julia. 2. Rcpp. 3. Mex files in Matlab. 21