programming ii -...

87
Lecture 1 Programming II Iztok Savnik, FAMNIT February, 2020. 1

Upload: others

Post on 19-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Lecture 1

Programming II

Iztok Savnik, FAMNIT

February, 2020.

1

Page 2: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Contents

• Course organization• History of programmiing languages• Concepts of programming languages• Meta-Language ML• Some benchmarks• Method and aims of course• What is happening in PL area?

Page 3: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Course organization

• Lectures– Iztok Savnik

• Exercises– Matjaž Krnc, László Hajdu

• Homeworks– Writting programs in Ocaml– 3 homeworks

Page 4: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

4

Grading

• Written exam – 40%• Oral exam – 30%• Homeworks – 30%

• Each part must be positive!

Page 5: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

1. John Mitchell, Concepts in Programming Languages, Cambridge Univ Press, 2003.

2. Iztok Savnik, Jan Karabas, Concepts of programming languages, Lecture notes (in English), FAMNIT, 2017.

3. Michael L. Scott, Programming Language Pragmatics (3rd ed.) Elsevier, 2009.

5

Literature

Page 6: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Overview of PL

• Assembler • Fortran • IPL, Cobol• Imperative languages

– Algol – Prog.language C– Pascal, Modula

• Functional languages– Lisp– ML– Haskell

• Object languages– C++, Objective C– Java, Eifel– Ruby

• High-level languages– Electronics– Information systems – Integration languages

• Script languages– System languages– Web languages– User interfaces– Python, Perl, PhP, JSP, ASP

• Prolog– Sicstus Prolog– SWI-Prolog– Datalog– Lambda Prolog

Page 7: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 8: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Charles Babbage

• The origins of the digital programmable computer– English mathematician, philosopher, inventor and

mechanical engineer.– In 1837 he has designed Analytical engine, the first

mechanical computer, that led to the design of more complex electronic computers.

• The anlytical engine– mechanical computation of arithmetic operations– branching – loops where the results of the previous computation

are taken as an input to the following iterations.

• Turing-complete machine

Page 9: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Electronic computers

• The first electromechanical computer – German civil engineer and inventor Konrad Zuse– Z1, Z2, Z3, 1936 and 1945, totally independent– Loops but no branching, shown to be Turing-complete

• General-purpose electronic computer.– 1943 University of Pennsylvania – ENIAC (Electronic Numerical Integrator and Computer)– 10 digit arithmetic, branching, loops, procedures

Page 10: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Electronic computers

• Mark 1, Mark 2, Mark 3– ASCC (Automatic Sequence Controlled Calculator) – Developed by Harvard University in 1944– Original concept presented to IBM by H.Aiken in 1937– Following Charles Babbage

• von Neumann architecture – Princeton arhitecture, 1945 – First Draft of a Report on the EDVAC– Principal abstraction, representation of the basic

function of computers• central processing unit, main memory and input/output devices

Page 11: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Plankalkuel

• The first programming language • Konrad Zuse

– German civil engineer and inventor – Floating-point mechanical digital calculator Z1– Improved versions Z2 and Z3 in 1941

• Telephone relays for memory• Presented to the public

• Concepts– Sequence of arithmetical operations– Loops included – No branching operation

Page 12: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

First compiler

• A-O programming language – Algorithmic Language version 0 – UNIVAC I computer– Grace Hopper in 1951, 1952

• Program in A-0 language was a sequence of subrutine calls together with the parameters

• The compiler was merely a linker and a loader• Followed by the A-1, A-2, A-3

– ARITH-MATIC, MATH-MATIC, FLOW-MATIC

Page 13: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Fortran

• First complete compiler• John W. Backus, 1953, IBM

– IBM 704 mainframe• Mathematical FORmula TRANslating System

– IBM 360• Constructs of Fortran

– DO, GOTO, IF, SUBRUTINE, CALL

• Numeric processing– Programs can be parallelized

• Followed by the imperative familiy– C, Pascal, Modula

• Fortran II, Fortran 77, Fortran III, Fortran 90, Fortran 95, Fortran 2003, ...

Page 14: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

FLOW-MATIC

• Bussiness Language version 0, or, B-0. – UNIVAC I at Remington Rand – Grace Hopper in 1955. – Bussiness does not like formulas → English language

• Hopper team developed compiler by 1959.– First language that made a clear distinction between

the data definition section and the code section of the

• Strong influence on the development of the programming language COBOL.

Page 15: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Information Processing Language

• Information Processing Language (IPL) – Allen Newell, Cliff Shaw and Herbert Simon– Rand Corporation in 1956. – Assembly language - operations manipulate lists

• IPL computer– Set of symbols, set of cells, set of primitive functions – Functions defined on the cells and lists – primitive PL run-time environment

• AI language– Abstract and suitable for expressing AI programs– Programs are not efficient

Page 16: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Algol

• Developed in ETH Zuerich, 1958.– Team of computer scientists from Europe and US

• Allan J. Perlis, Peter Naur, John McCarthy, and others

– Originally: Algebraic Language, or, IAL– Avoided problems percived in FORTRAN

• Contributions– John Backus developed BNF to specify ALGOL 58– Formal semantics, two parameter passing methods:

cbv and cbr, code blocks, nested functions, lexical scope

– Imperative effect of cbr to lambda calculus studied

• Influence: – Pascal, C, Modula, Java, ...

C.A.R. Hoare: "Here is a language so far ahead of its time

that it was not only an improvement on its predecessors but

also on nearly all its successors."

Page 17: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Lisp• Developed by John McCarthy at MIT, 1958• Lisp is based on lambda calculus

– Alonzo Church in 1930 – Church's paper on undecidable problem– Strongly influenced by IPL – Lists used for representation of programs and data

• New concepts– Automatic storage management, dynamic typing, self-

hosting compiler, and others.

• AI language– Second-oldest programming language that is still in use

• Common Lisp and Scheme.

Page 18: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Cobol

• Designed by CODASYL, 1959– Conference/Committee on Data Systems Languages– Previous work of Grace Murray Hopper

• Programming language for bussiness applications– Imperative and procedural– Since 2002, object-oriented

• A compiled English-like programming language – Awkward syntax– Cobol pograms work today! – Syntax has been changed

Page 19: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

C Programming Language

• Dennis Ritchie, Bell Laboratories, 1972– C designed for– Language B, based on BCPL

• Language constructs– Algol family – Still one of best languages (C++ =? C + object illusion)– Close to hardware, system programming

• Arrays and references are closely related– E1[E2] = ]*((E1)+(E2))– Adress arithmetic

• Ritchie wrote:– “C is quirky, flawed, and a tremendous success.”

Page 20: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Pascal

• Niklaus Wirth, ETH Zürich, 1970• Very popular in Europa• Structred programming language

– Algol family– Data structures, pointers, arrays, variable records, ...…

• Many implementations– VAX Pascal, Turbo Pascal, …– Delphi: nice programming environment

• Modula-2, Modula-3, Oberon

Page 21: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Language sequences

Algol 60

Algol 68

Pascal

ML Modula

Lisp

Page 22: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Functional languages

• Rooted in logic– Lambda calculus, 1930, Alonzo Church

• LISP – John McCarthy– Implementation of lambda calculus

• Meta-Language– ML, Rob Milner

• Functional languages are more appropriate for teaching? – Strong typing– Program is proof– Elements of declarative programming– USA

Page 23: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

History of ML

• Logic for computable functions (LCF)– Robin Milner, Dana Scott– Stanford 1970-71, Edinburgh 1972-1995

• Meta-language for LCF system– Automatization of logic reasoning– Proofs– Type systems– Notation for programs– Higher-order functions– Programs that search for proof

Page 24: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Object-Oriented Languages

• First OO language is Simula.– Simulation programming environment

• Smalltalk is one of the most famous OO languages– Adele Goldberg, Xerox, Palo Alto– Everything is object !

• Every object belongs to one class – Class is prototype object– Class is object !– Complex inheritance hierarchies

• C++, Java, Objective C, ...• Java

– J.Gosling, B.Joy, G.Steele, G.BrachaThe Java Language Specification

https://docs.oracle.com/javase/specs/

Page 25: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Script languages

• Web programming languages– V zadnjih letih se je pojavila množica jezikov, za delo

na Web strežnikih– JSP, PhP, JavaScript, ASP, …– Reseources of Web server

• System programming languages– Strong ties to OS – C + Awk, Perl, Python

• System integration languages

Page 26: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

High-level languages

• Information systems– 4GL, PL/SQL, SQL3– UML (specifikacije)

• Electronics– VHDL, EDIF, ...

Page 27: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Prolog

• Programming in Logic, Robert Kowalski• Predicate calculus

– Horn clauses– Unification, resolution

• Strong, simple and abstract language• Back-tracking

– Declarative and procedural semantics of Prologa– Operator CUT (!)

• Database programming languages– Datalog

• Sicstus, SB Prolog, SWI Prolog,…

Page 28: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Concepts in programming languages

• Programming language is programming tool, defined in the form of language, that is used for design and implementation of computer programs.

• Concepts of programming languages are abstractions used for representation of structure and behaviour of modelled systems.

Page 29: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Abstraction

• In Philosophy– Specific operation of the intellect consisting in

detaching and retaining some property from a thing

• Aristotel – Constructive mental process associated with the

relation between forms (ideas) and concrete objects– Human mind actively abstracts or extracts forms from

the objects in which they are realized

• St. Thomas Aquinas– Two kinds of abstractions– Mind joins properties that are separate from each other– Mind separates properties that are one

Page 30: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Concepts in programming languages

• Abstractions integrated into the language – Function, object, method, class, abstract class, ...,

classification, specialization, aggregation, ...

• Abstractions define language model – Imperative languages: variables, loops, procedures, ...– Functional languages: functions– Object languages: object and classes

Page 31: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Classifications of PL concepts

• Algorithmic and data abstractions– Algorithmic abstractions

• Itaration statements, patterns, recursion, ... – Data abstractions

• N-tuples, lists, recursive data structures

• Language and implementation concepts – Language abstractions

• Functions, objects, methods, inheritance, ...

– Implementation abstractions • Memory management, parameter passing, ...

Page 32: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Implementation concepts

• We learn about the implementation of PL constructs– Representation of variables, data structures, ...– Memory management

• Memory organization • Garbage collection

– Implementation of PL concepts • Functions in C, Java, Ocaml, ...• Parameters in C, Java, Ocaml, ...• Classes in Java, OCaml, ...

Page 33: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Properties of abstractions in PL

• Closer to hardware, more simple languages• Simple abstractions:

– Numbers, characters, loops, routines, ....

• Higher abstractions: – Objects, modules, ...

• Higher level of abstraction in PL: – More directed language– Very general abstractions - more specific language

• General programming language is in the middle: – Wide applicability – General-purpose PL– Very complex languages

Page 34: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Abstractions

• Study of abstractions can improve learning process – COMMUNICATIONS OF THE ACM April 2007/Vol. 50, No. 4

IS ABSTRACTION THE KEY TO COMPUTING?

Page 35: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 36: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Why to study concepts in PL?

We learn about the possible ways of expressing ideas.

We learn how to use given PL abstractions correctly.

– You have to know the tool– It is good to have formal background– It is good to have experiences with using tools

Page 37: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Meta-Language

• Meta Language (ML) – Developed unintentionally while working on system

for automatic theorem proving based on LCF - Logic of computable functions.

• LCF is a version of lambda calculus– Initially at Edinburg University– Later in AI group of Stanford University – Project leader was Robin Milner.

• Meta-Language was used as language for expressing mathematical proofs– They would change the files with proofs to obtain

better proof

Page 38: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Meta-Language

• Success story from functional branch of programming languages

• Standard ML, SML/NJ, Alice ML, Ocaml, Moscow ML, Mlton, MLKit, SML.NET, ...

• Research related to ML– Hindley-Milner type-checking algorithm – Polimorfic lambda calculus (System F, Girard)

Page 39: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Lambda calculus

• Lambda calculus is the foundamental formalism for studying programming languages

• Theory of programming languages– Using rule-based reasoning for:

• deriving expression types,• evaluation of expressions, • Prooving the properties of language, etc.

– Static and dynamic semantics of PL – Prooving the properties of languages (determinism,

strict typing, termination, etc.).

• Labda calculus is topic of one lecture

Page 40: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Objective Caml

• Objective Caml is reference language– Caml core is pure lambda calculus.– Theoretically well-studied language.– Caml has strong typing.– Imperative constructs. – Parametric polymorphism– Nice object model– Modules and functors

• Ocaml offers more than one programming models– Imperative + functional + object-oriented + modular

programming model

Page 41: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

communications of the acm| november 2 0 1 1 | vo l . 5 4 | n o. 1 1

Page 42: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 43: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Who uses OCaml

• Facebook

• Jane Street

• Bloomberg, Citrix, …• See: https://ocaml.org/learn/companies.html

Page 44: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

F#

• F# is like C# – .NET language– F# is based on OCaml– C# is C-like language, similar to Java and C++ …

• Features– Lightweight syntax– Immutable by default– Type inference and automatic generalization– First-class functions– Powerful data types– Pattern matching– Async programming

Page 45: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Courses taught in OCamlhttps://ocaml.org/learn/teaching-ocaml.html

Page 46: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Courses taught in OCaml

https://ocaml.org/learn/teaching-ocaml.html

Page 47: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Comparisons of PL

• Codeval comparison• A Comparison of Programming Languages in

Economics• In-Deman Programming languages• The Computer Language Benchmarks Game• Githut• TIOBE Index

Page 48: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 49: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 50: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 51: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 52: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 53: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

A Comparison of Programming Languages in Economics, Aruoba and Fernandez-Villaverde, 2014

Page 54: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2016/

Page 55: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2017/

Page 56: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

http://www.codingdojo.com/blog/7-most-in-demand-programming-languages-of-2018/

Page 57: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

https://www.codingdojo.com/blog/the-7-most-in-demand-programming-languages-of-2019

Page 58: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

https://www.infoworld.com/article/2840235/application-development/9-cutting-edge-programming-languages-worth-learning-next.html

• Kotkin: Java reconsidered

• Erlang: Functional programming for real-time systems

• Go: Simple and dynamic

• OCaml: Complex data hierarchy juggler

• TypeScript: JavaScript you’ll like

• Rust: Safe and usable systems language

• ...

Page 59: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

The Computer Language Benchmarks Game

• 33 languages, 4 systems, 13 test programs• http://benchmarksgame.alioth.debian.org/

Page 60: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 61: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

• High-level programming languages can be very efficient• Java and Ocaml are efficient languages

Page 62: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 63: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 64: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

https://sites.google.com/view/energy-efficiency-languages/homehttp://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sleFinal.pdf

Energy Efficiency across Programming Languages: How does Energy, Time and Memory Relate?

Page 65: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

https://sites.google.com/view/energy-efficiency-languages/homehttp://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sleFinal.pdf

Energy Efficiency across Programming Languages: How does Energy, Time and Memory Relate?

Page 66: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Speed, size and memory usage of PL

429 programs

13 test programs

33 PL

Experiment:

Guillaume Marceau

Page 67: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 68: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

githut

• Programming languages on github, 2014• http://githut.info/• 2M active repositories• Parameters

– No. of projects on github– No. of push operations– No. of push/repository operations– No. of fork operations– No. of opened issues– No. of watchers

68

Page 69: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 70: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 71: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

TIOBE Indeks

• https://www.tiobe.com/tiobe-index/• Indeks based on:

– Web search engines: Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube, Baidu

• TIOBE index is NOT:– About best PL– About the most used PL

71

Page 72: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 73: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 74: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 75: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 76: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus
Page 77: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Aims of course

• Concepts of programming languages– Language is »conceptual universe” (Perlis)– Framework for solving problems – Usefull concepts and constructs of PLs

• Learning more than one PL– It is good to know the history !– Learning concepts from sources– Efficient usage of PL constructs

77

Page 78: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Methods • Lambda calculus

– Formal foundation – Basic principles of procedural PL– Lisp: first programming language based on LC

• ML – Mathematical foundations – Strong typing– Includes most PL constructs

• Java + C– Languages to compare ML!– C is still the most popular language– Java uses clean object-oriented model– Strong typing and dynamic typing

78

Page 79: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Methods

• First classification = language model– Functional, imperative, object, module

• Some concepts will be put forward– Functions, parameters, types, scope, control, data

abstractions, inheritancem polimorphism, memory– We will see diferent approaches– Languages used: C, ML, Java– Sometimes: Pascal, Fortran, C++, Ada

• Comparison of PL concepts – We know what we can use– Concepts can also be very different

79

Page 80: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

Method

• Learning about PL constructs and implementation– Every construct has its price– It always good to know what is happening »below« – Efficient use of constructs

• Many times it is neccessary to know implementation of concepts– Memory management– Representation of data structures– Implementation of functions and recursion– Dynamic aspects of languages

80

Page 81: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What is happening in PL area?

• Trendy applications– Complex programming systems– Telecommunications– Parallel programming– Data mining/data science– Supercomputers– Visual/dataflow programming– Artificial intelligence

81

Page 82: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What is happening in PL area?

• Classical high-level PL– Java, C++, C, C#, …

• Script/system languages– Python, Perl, Lua, Rust, ...

• Abstract but efficient PL– Scala, Swift, Ruby, Go, ….

• Increased use of functional languages– Haskell, F#, Ocaml, Erlang, ML, ...– Increased use of functional concepts

• Java, C++, Scala, Ruby, Python, ...

• Data programming languages– R, Julia, Mathlab, SAS ... 82

Page 83: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What is happening in PL area?

• Java is replacing C and C++? • C, C++ is replacing Java?• Python as the first language?• Lisp/Schema still first language?• C is coming back?• Practical languages

– Python in schools?– Strong programming environments– Strong open-source support

83

Page 84: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What is happening in PL area?

• Research trends– Strong typing, dynamic typing– Dynamic and JIT optimization– Compilers and multicore programming challenge– Parallel programming– Program graph analysis for parallelization– Meta-programming

84

Page 85: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What is happening in PL area?

• Programming languages for target systems– Mobile phones, iPad, – El.machines, TV, car, washing machine, …

• Concurrent PL – Erlang, Concurrent ML, E, CAL, ...– Dataflow programming– Multi-processor, multi-threaded prgramming

85

Page 86: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What is happening in PL area?

• More formal analysis used– Type-checking, static and dynamic typing, program

analysers, diagnostics, …

• Abstract VM– Additional level of abstraction: Virtual Machine– Java VM, Erlang VM (BEAM), ...– Portability

• Meta-pogramming languages– Coq, Isabelle, Twelf– Languages used to analyse, test and implement other

programming languages

86

Page 87: Programming II - osebje.famnit.upr.siosebje.famnit.upr.si/~savnik/predmeti/Prog2/Introduction.pdf · Lisp • Developed by John McCarthy at MIT, 1958 • Lisp is based on lambda calculus

What to learn?

• Most commonly used PLs– C, C++, Java, Python

• Concepts of PLs• Important implementation ideas• New trends

– New languages: R, VimL, Go, Swift, Scala– Functional constructs: Haskell, Ruby, C++, Java

• Design decisions – trade-offs– Functional vs. imperative, modular vs. object-oriented, ...

87