introduction (part 3) programming...
TRANSCRIPT
![Page 1: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/1.jpg)
1
Prof. Dr. Michael Pradel
Software Lab, University of StuttgartSummer 2020
Programming ParadigmsIntroduction (Part 3)
![Page 2: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/2.jpg)
2
Overview
� Motivation� What the course is about� Why it is interesting� How it can help you
� Organization� Exercises� Grading
� Introduction to ProgrammingLanguages� History, paradigms, compilation, interpretation
![Page 3: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/3.jpg)
3 - 1
History: From Bits ...
First electronic computers: Programmedin machine language� Sequence of bits
� Example: Calculate greatest common divisor
![Page 4: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/4.jpg)
3 - 2
History: From Bits ...
First electronic computers: Programmedin machine language� Sequence of bits
� Example: Calculate greatest common divisor
Machine time more valuable thandeveloper time
![Page 5: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/5.jpg)
4 - 1
... over Assembly ...
Human-readable abbreviations formachine language instructions
� Less error-prone, but still very machine-centered
� Each new machine: Different assembly language
� Developer thinks in terms of low-level operations
![Page 6: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/6.jpg)
4 - 2
... over Assembly ...
Greatest common divisor in x86:
![Page 7: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/7.jpg)
5 - 1
... to High-level Languages
� 1950s: First high-level languages� Fortran, Lisp, Algol
� Developer thinks in mathematical andlogical abstractions
![Page 8: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/8.jpg)
5 - 2
... to High-level Languages
subroutine gcd_iter(value, u, v)integer, intent(out) :: valueinteger, intent(inout) :: u, vinteger :: t
do while( v /= 0 )t = uu = vv = mod(t, v)
enddovalue = abs(u)
end subroutine gcd_iter
Greatest common divisor in Fortran:
![Page 9: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/9.jpg)
6 - 1
Today: 1000s of Languages
� New languages gain traction regularly
� Some long-term survivors
� Fortran, Cobol, C
![Page 10: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/10.jpg)
6 - 2
Today: 1000s of Languages
� New languages gain traction regularly
� Some long-term survivors
� Fortran, Cobol, C
Poll (in Ilias):Your favorite programming language?
![Page 11: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/11.jpg)
7
What Makes a PL Successful?
� Expressive power� But: All PLs are Turing-complete
� Ease of learning (e.g., Basic, Python)� Open source� Standardization: Ensure portability
across platforms� Excellent compilers� Economics
� E.g., C# by Microsoft, Objective-C by Apple
![Page 12: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/12.jpg)
8
PL Spectrum
� Broad classification� Declarative (”what to compute”):
E.g., Haskell, SQL, spreadsheets
� Imperative (”how to compute it”):E.g., C, Java, Perl
� Various PL paradigms:
� Most languages combine multipleparadigms
Functional
Logic
Statically typedDynamically typed
Sequential
Shared-memoryparallel
Distributed-memoryparallel
Dataflow
![Page 13: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/13.jpg)
9 - 1
Example: Imperative PL
C implementation for GCD:
int gcd(int a, int b) {
while (a != b) {
if (a > b) a = a - b;
else b = b - a;
}
return a;
}
![Page 14: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/14.jpg)
9 - 2
Example: Imperative PL
C implementation for GCD:
int gcd(int a, int b) {
while (a != b) {
if (a > b) a = a - b;
else b = b - a;
}
return a;
}
Statements thatinfluence subsequentstatements
![Page 15: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/15.jpg)
9 - 3
Example: Imperative PL
C implementation for GCD:
int gcd(int a, int b) {
while (a != b) {
if (a > b) a = a - b;
else b = b - a;
}
return a;
}
Statements thatinfluence subsequentstatements
Assignments withside effect ofchanging memory
![Page 16: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/16.jpg)
10 - 1
Example: Functional PL
OCaml implementation of GCD
let rec gcd a b =
if a = b then a
else if a > b then gcd b (a - b)
else gcd a (b - a)
![Page 17: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/17.jpg)
10 - 2
Example: Functional PL
OCaml implementation of GCD
let rec gcd a b =
if a = b then a
else if a > b then gcd b (a - b)
else gcd a (b - a)
Recursive functionwith two arguments
![Page 18: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/18.jpg)
10 - 3
Example: Functional PL
OCaml implementation of GCD
let rec gcd a b =
if a = b then a
else if a > b then gcd b (a - b)
else gcd a (b - a)
Recursive functionwith two arguments
Focus onmathematicalrelationship betweeninputs and outputs
![Page 19: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/19.jpg)
11 - 1
Example: Logic PL
Prolog implementation of GCD
gcd(A,B,G) :- A = B, G = A.
gcd(A,B,G) :- A > B, C is A-B, gcd(C,B,G).
gcd(A,B,G) :- B > A, C is B-A, gcd(C,A,G).
![Page 20: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/20.jpg)
11 - 2
Example: Logic PL
Prolog implementation of GCD
gcd(A,B,G) :- A = B, G = A.
gcd(A,B,G) :- A > B, C is A-B, gcd(C,B,G).
gcd(A,B,G) :- B > A, C is B-A, gcd(C,A,G).
Facts and rules
![Page 21: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/21.jpg)
11 - 3
Example: Logic PL
Prolog implementation of GCD
gcd(A,B,G) :- A = B, G = A.
gcd(A,B,G) :- A > B, C is A-B, gcd(C,B,G).
gcd(A,B,G) :- B > A, C is B-A, gcd(C,A,G).
Facts and rules
Focus on logicalrelationshipsbetween variables
![Page 22: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/22.jpg)
12
Compilation and Interpretation
Different ways of executing a program
� Pure compilation
� Pure interpretation
� Mixing compilation and interpretation
� Virtual machines
� Just-in-time compilation
![Page 23: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/23.jpg)
1
![Page 24: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/24.jpg)
2
![Page 25: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/25.jpg)
3
![Page 26: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/26.jpg)
17
PL Design vs. Implementation
� Some PLs are easier to compile thanothers
� E.g., runtime code generation
� Code to execute: Unknown at compile time
� Hard to compile
� Easy to interpret
![Page 27: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/27.jpg)
19
Other Tools
� Linkers
� Preprocessors
� Source-to-source compilers
![Page 28: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/28.jpg)
4
![Page 29: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/29.jpg)
5
![Page 30: Introduction (Part 3) Programming Paradigmssoftware-lab.org/teaching/summer2020/pp/slides_01_introduction_03... · Programming Paradigms Introduction (Part 3) 2 Overview Motivation](https://reader034.vdocument.in/reader034/viewer/2022051815/603e584b7ebbcf6fae29a9f2/html5/thumbnails/30.jpg)
6