50
1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter 2019/2020 Programming Paradigms Lecture 1: Introduction Join the course on Ilias! See link on http://software-lab.org/teaching/winter2019/pp/

Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

1

Prof. Dr. Michael Pradel

Software Lab, University of StuttgartWinter 2019/2020

Programming ParadigmsLecture 1: IntroductionJoin the course on Ilias! See link onhttp://software-lab.org/teaching/winter2019/pp/

Page 2: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

2

About Me: Michael Pradel

� Since 9/2019: Full Professorat University of Stuttgart

� Before� Studies at TU Dresden, ECP (Paris),

and EPFL (Lausanne)� PhD at ETH Zurich, Switzerland� Postdoctoral researcher at UC Berkeley, USA� Assistant Professor at TU Darmstadt� Sabbatical at Facebook, Menlo Park, USA

Page 3: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

3

About the Software Lab

� My research group since 2014� Focus: Tools and techniques for

building reliable, efficient, and securesoftware� Program testing and analysis� Machine learning, security

� Thesis and job opportunities

Page 4: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

4

Plan for Today

� Motivation� What the course is about� Why it is interesting� How it can help you

� Organization� Exercises� Grading

� Introduction� Programming languages:

History, paradigms, compilation, interpretation

Page 5: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

5

The Role of Programming

� Programming: Essential form ofexpression for a computer scientist� ”The limits of my language mean the limits of

my world.” (Ludwig Wittgenstein)

� Programming languages determinewhat algorithms and ideas you canexpress

Page 6: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

6

Goal of this Course

Understand how programminglanguages (PLs) work

� How are languages defined?

� What language design choices exist?

� How are languages implemented?

Page 7: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

7

Why Learn About PLs?

Enables you to

� choose right PL for a specific purpose

� choose among alternative ways to express things

� make best use of tools (e.g., debuggers, IDEs,analysis tools)

� understand obscure language features

� simulate useful features in languages that lack

them

Page 8: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

8

Concepts vs. Languages

This course is not about

� All details of a specific language

� A systematic walk through a set of languages

Instead, this course is about

� Concepts underlying many languages

� Various languages as examples

Page 9: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

9 - 1

Isn’t Knowing {Pick a PL} Enough?

� Complex systems: Built in variouslanguages

� E.g., Facebook: Wild mix of languages

covering various language paradigms

� New languages arrive regularly (andold ones fade away)

Page 10: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

9 - 2

Isn’t Knowing {Pick a PL} Enough?

� Complex systems: Built in variouslanguages

� E.g., Facebook: Wild mix of languages

covering various language paradigms

� New languages arrive regularly (andold ones fade away)

Page 11: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

10

Plan for Today

� Motivation� What the course is about� Why it is interesting� How it can help you

� Organization� Exercises� Grading

� Introduction� Programming languages:

History, paradigms, compilation, interpretation

Page 12: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

11

Language

� Written material (slides, exercises):English

� Lectures: German

� Exercise sessions: German andEnglish

� Final exam: Questions in English,answers in German or English

Page 13: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

12

Lectures

Two weekly slots (Monday and Friday)

� But: Not all slots used

� See course page for schedule:

http://software-lab.org/teaching/winter2019/pp/

Slides and hand-written notes:

� Available shortly after each lecture

Page 14: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

13

Exercises

� Six graded exercises

� We publish on day X� On the course page

� You submit your solution by day X+7� Via Ilias

� Solutions are discussed in exercisesessions starting from day X+8

Page 15: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

14

Exercise Sessions

� Ten exercise groups� See C@mpus for date and location

� Groups 1, 5, 6, 7, 10: English

� Groups 2, 3, 4, 8, 9: German

� Your recommended exercise group� Last digit of matriculation number + 1

� You can also go elsewhere

� But: If not enough space, priority given to

students in ”their” group

Page 16: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

15

Ilias

Platform for discussions, in-classquizzes, and sharing additional material

� Please register for the course� Use it for all questions related to the course� Messages sent to all students go via Ilias

Link to Ilias course onsoftware-lab.org/teaching/winter2019/pp/

Page 17: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

16

Quizzes During the Lectures

� A few quizzes during each lecture� Check your understanding

� Answer are anonymous and not graded

� Access quizzes via Ilias

� https://ilias3.uni-stuttgart.de/vote/0ZT9

Page 18: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

17

Questions and Discussions

For any (non-personal) questions:Use forum in Ilias

� English or German

� Encouraged: Answer each other

� Teaching assistants and me are monitoring it

Page 19: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

18

Grading

� Exercises: Passing is prerequisite forfinal exam� Each exercise: Same number of points

� Skipping exercises: Okay, but zero points

� Minimum number of points

� Your points: Published at end of semester

� Final exam: Open book� All printed and hand-written material allowed

(incl. slides, textbooks, and a dictionary)

� Tests your understanding, not your knowledge

Page 20: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

19

Reading Material

� No script or book covers everything� Most relevant book: Programming Language

Pragmatics by Michael L. Scott

� Also interesting: Concepts of ProgrammingLanguages by Robert W. Sebesta

� Pointers to book chapters and webresources: Course page

Page 21: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

20

Plan for Today

� Motivation� What the course is about� Why it is interesting� How it can help you

� Organization� Exercises� Grading

� Introduction� Programming languages:

History, paradigms, compilation, interpretation

Page 22: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

21 - 1

History: From Bits ...

First electronic computers: Programmedin machine language

� Sequence of bits

� Example: Calculate greatest common divisor

Page 23: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

21 - 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 24: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

22 - 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 25: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

22 - 2

... over Assembly ...

Greatest common divisor in x86:

Page 26: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

23 - 1

... to High-level Languages

� 1950s: First high-level languages� Fortran, Lisp, Algol

� Developer thinks in mathematical andlogical abstractions

Page 27: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

23 - 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 28: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

24 - 1

Today: 1000s of Languages

� New languages gain traction regularly

� Some long-term survivors

� Fortran, Cobol, C

Page 29: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

24 - 2

Today: 1000s of Languages

� New languages gain traction regularly

� Some long-term survivors

� Fortran, Cobol, C

Poll:Your favorite programming language?

https://ilias3.uni-stuttgart.de/vote/0ZT9

Page 30: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

25

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 31: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

26

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 32: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

27 - 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 33: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

27 - 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 34: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

27 - 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 35: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

28 - 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 36: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

28 - 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 37: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

28 - 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 38: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

29 - 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 39: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

29 - 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 40: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

29 - 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 41: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

30

Compilation and Interpretation

Different ways of executing a program

� Pure compilation

� Pure interpretation

� Mixing compilation and interpretation

� Virtual machines

� Just-in-time compilation

Page 42: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

1

Page 43: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

2

Page 44: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

3

Page 45: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

35

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 46: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

37

Other Tools

� Linkers

� Preprocessors

� Source-to-source compilers

Page 47: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

4

Page 48: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

5

Page 49: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

6

Page 50: Lecture 1: Introduction Programming Paradigmssoftware-lab.org/teaching/winter2019/pp/lecture_introduction.pdf · 1 Prof. Dr. Michael Pradel Software Lab, University of Stuttgart Winter

41

Plan for Today

� Motivation� What the course is about� Why it is interesting� How it can help you

� Organization� Exercises� Grading

� Introduction� Programming languages:

History, paradigms, compilation, interpretation4