programming ii -...
TRANSCRIPT
Lecture 1
Programming II
Iztok Savnik, FAMNIT
February, 2020.
1
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?
Course organization
• Lectures– Iztok Savnik
• Exercises– Matjaž Krnc, László Hajdu
• Homeworks– Writting programs in Ocaml– 3 homeworks
4
Grading
• Written exam – 40%• Oral exam – 30%• Homeworks – 30%
• Each part must be positive!
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
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
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
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
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
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
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
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, ...
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.
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
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."
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.
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
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.”
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
Language sequences
Algol 60
Algol 68
Pascal
ML Modula
Lisp
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
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
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/
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
High-level languages
• Information systems– 4GL, PL/SQL, SQL3– UML (specifikacije)
• Electronics– VHDL, EDIF, ...
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,…
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.
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
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
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, ...
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, ...
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
Abstractions
• Study of abstractions can improve learning process – COMMUNICATIONS OF THE ACM April 2007/Vol. 50, No. 4
IS ABSTRACTION THE KEY TO COMPUTING?
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
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
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)
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
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
communications of the acm| november 2 0 1 1 | vo l . 5 4 | n o. 1 1
Who uses OCaml
• Jane Street
• Bloomberg, Citrix, …• See: https://ocaml.org/learn/companies.html
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
Courses taught in OCamlhttps://ocaml.org/learn/teaching-ocaml.html
Courses taught in OCaml
https://ocaml.org/learn/teaching-ocaml.html
Comparisons of PL
• Codeval comparison• A Comparison of Programming Languages in
Economics• In-Deman Programming languages• The Computer Language Benchmarks Game• Githut• TIOBE Index
A Comparison of Programming Languages in Economics, Aruoba and Fernandez-Villaverde, 2014
http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2016/
http://www.codingdojo.com/blog/9-most-in-demand-programming-languages-of-2017/
http://www.codingdojo.com/blog/7-most-in-demand-programming-languages-of-2018/
https://www.codingdojo.com/blog/the-7-most-in-demand-programming-languages-of-2019
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
• ...
The Computer Language Benchmarks Game
• 33 languages, 4 systems, 13 test programs• http://benchmarksgame.alioth.debian.org/
• High-level programming languages can be very efficient• Java and Ocaml are efficient languages
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?
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?
Speed, size and memory usage of PL
429 programs
13 test programs
33 PL
Experiment:
Guillaume Marceau
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
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
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
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
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
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
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
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
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
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
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
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
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