48
Einführung in die Informatik 2. Programming Languages, Paradigms and Technology Institut für Informatik und angewandte Mathematik

Einführung in die Informatik 2. Programming Languages, Paradigms and Technology Institut für Informatik und angewandte Mathematik

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Einführung in die Informatik

2. Programming Languages, Paradigms and Technology

Institut für Informatik und angewandte Mathematik

© Oscar Nierstrasz 2

Roadmap

> What is a programming language?> Programming = modeling> Evolution> Trends and Challenges

Programming Languages, Paradigms and Technology

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

3

Übersicht

Informatik

Theorie(Automaten und formale Sprachen, Berechenbarkeit, Komplexität, Logik, Algorithmen)

Praxis(Programmiersprachen, Betriebssysteme, Netzwerke &Verteilte Systeme, Software Engineering, Datenbanken, Rechnerarchitektur)

Schnittstellen zur Aussenwelt(Mensch-Maschine Schnittstelle, Computer-vision, Computergrafik, Sensornetze, Künstliche Intelligenz, Computerlinguistik)

Wirtschaftsinformatik

Anwendungs-software

Wissenschaftliche Anwendungen(Modellierung und Simulation, Biologie, Physik, Chemie, Sozialwissenschaften, etc.)

Informatikstudium Andere Studiengänge

Mathematik

Programmiersprachen

formaleSprachen

Computerlinguistik

Modellierung

SoftwareEngineering

© Oscar Nierstrasz 4

Roadmap

> What is a programming language?> Programming = modeling> Evolution> Trends and Challenges

Programming Languages, Paradigms and Technology

What is a language?

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

5

Language = a set of sequences of symbols that we interpret to attribute meaning

Jack and Jill went up the hill …Jack and Jill went up the hill …

What is a formal language?

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

6

A Turing machine reads (and writes) a tape of 0s and 1sA Turing machine reads (and writes) a tape of 0s and 1s

The language it accepts is the set of strings that leave it in an accepting stateThe language it accepts is the set of strings that leave it in an accepting state

How can we describe formal languages?

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

7

expression numberexpression expression + expression expression expression expressionnumber digitnumber digit number

expression numberexpression expression + expression expression expression expressionnumber digitnumber digit number

Use a set of rules ( ) to describe the structure of the languageUse a set of rules ( ) to describe the structure of the language

3 + 4 53 + 4 5

cf. Chomsky

What is a Programming Language? (take 1)

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

8

.-…-…-….-…---.---..-l.-..-.-. .-…-…-….-…---.---..-l.-..-.-.

.-…-…-….-…---.---..-l.-..-.-. .-…-…-….-…---.---..-l.-..-.-.

12368759752465426856875428654482654876578655123687597524654268568754286544826548765786551236875975246542685687542865448265487657865…

A language to instruct a computer to compute “stuff” …A language to instruct a computer to compute “stuff” …

But how does the computer interpret language?But how does the computer interpret language?

What is a Programming Language? (take 2)

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

9

.-…-…-….-…---.---..-l.-..-.-. .-…-…-….-…---.---..-l.-..-.-.

.-…-…-….-…---.---..-l.-..-.-. .-…-…-….-…---.---..-l.-..-.-.

What the compiler will handle …What the compiler will handle …

0100100101100110010001110101011010000110101010100101111001111100010101000101011…

0100100101100110010001110101011010000110101010100101111001111100010101000101011…

But what about syntax and semantics?But what about syntax and semantics?

parse

analyze

transform optimizegenerate

What is a Programming Language? (take 3)

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

10

.-…-…-….-…---.---..-l.-..-.-. .-…-…-….-…---.---..-l.-..-.-.

.-…-…-….-…---.---..-l.-..-.-. .-…-…-….-…---.---..-l.-..-.-.

Syntax and semantics in a mathematical domain …Syntax and semantics in a mathematical domain …

But what about the programmer?But what about the programmer?

What is a Programming Language? (take 4)

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

11

A language for communicating software designsA language for communicating software designs

© Oscar Nierstrasz 12

Roadmap

> What is a programming language?> Programming = modeling> Evolution> Trends and Challenges

Programming Languages, Paradigms and Technology

Over 8000 recorded programming languages

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

13

http://hopl.murdoch.edu.au/

Why so many?!Why so many?!

What do programming languages have in common?

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

14

# Compute factorialsdef fact(n) if n == 0 1 else n * fact(n-1) endend

puts fact(ARGV[0].to_i)

# Compute factorialsdef fact(n) if n == 0 1 else n * fact(n-1) endend

puts fact(ARGV[0].to_i)

commentscomments

keywordskeywords

functionsfunctionsvariablesvariables

control constructscontrol constructs

numbers, stringsnumbers, strings

expressionsexpressions

statementsstatements

A fragment of Ruby codeA fragment of Ruby code

Expressive power

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

15

Formally, all programming languages are equivalent …Formally, all programming languages are equivalent …

So what? …So what? …

Programming is modeling

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

16

How do these languages differ?

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

17

FunctionalFunctional

Object-orientedObject-orientedLogicLogic

ImperativeImperative

© Oscar Nierstrasz 18

Roadmap

> What is a programming language?> Programming = modeling> Evolution> Trends and Challenges

Programming Languages, Paradigms and Technology

Jacquard loom — 1801

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

19

Punch cards are inventedPunch cards are invented

Babbage’s Analytical Engine — 1822

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

20

The first mechanical computerThe first mechanical computer

Church’s Lambda Calculus — 1932

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

21

(λ x. (λ y. x)) a b(λ x. (λ y. x)) a b

The first (minimal) language for studying computationThe first (minimal) language for studying computation

(λ y. a) b (λ y. a) b

a a

if true then a else bif true then a else b

Turing machine — 1936

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

22

The first abstract model of a computer The first abstract model of a computer

1st generation: Machine code — 1944

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

23

Machine code is only meant to be read by … machines

Machine code is only meant to be read by … machines

Subroutines — 1949

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

24

The subroutine is one of the key concepts of programmingThe subroutine is one of the key concepts of programming

callcall

returnreturn

2nd generation: assembler — early 1950s

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

25

Assembly code introduces symbolic names (for humans!)Assembly code introduces symbolic names (for humans!)

3rd generation: FORTRAN — 1955

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

26

High-level languages are bornHigh-level languages are born

C AREA OF A TRIANGLE - HERON'S FORMULAC INPUT - CARD READER UNIT 5, INTEGER INPUTC OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUTC INPUT ERROR DISPAY ERROR OUTPUT CODE 1 IN JOB CONTROL LISTING INTEGER A,B,C READ(5,501) A,B,C 501 FORMAT(3I5) IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1 S = (A + B + C) / 2.0 AREA = SQRT( S * (S - A) * (S - B) * (S - C)) WRITE(6,601) A,B,C,AREA 601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS) STOP END

C AREA OF A TRIANGLE - HERON'S FORMULAC INPUT - CARD READER UNIT 5, INTEGER INPUTC OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUTC INPUT ERROR DISPAY ERROR OUTPUT CODE 1 IN JOB CONTROL LISTING INTEGER A,B,C READ(5,501) A,B,C 501 FORMAT(3I5) IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1 S = (A + B + C) / 2.0 AREA = SQRT( S * (S - A) * (S - B) * (S - C)) WRITE(6,601) A,B,C,AREA 601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS) STOP END

IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1S = (A + B + C) / 2.0AREA = SQRT( S * (S - A) * (S - B) * (S - C))

ALGOL — 1958

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

27

begin...

end

begin...

end

Block structureBlock structure

<statement> ::= <unconditional statement>| <conditional statement>| <for statement>

...

<statement> ::= <unconditional statement>| <conditional statement>| <for statement>

...

BNFBNF

RecursionRecursion

Lisp — 1958

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

28

(defun factorial (n) (if (= n 1) 1 (* n (factorial (- n 1)))))

(defun factorial (n) (if (= n 1) 1 (* n (factorial (- n 1)))))

Programs as dataPrograms as data

Garbage collectionGarbage collection

COBOL — 1959

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

29

modulesmodules

ADD YEARS TO AGE.MULTIPLY PRICE BY QUANTITY GIVING COST.SUBTRACT DISCOUNT FROM COST GIVING FINAL-COST.

ADD YEARS TO AGE.MULTIPLY PRICE BY QUANTITY GIVING COST.SUBTRACT DISCOUNT FROM COST GIVING FINAL-COST.

10 INPUT "What is your name: ", U$20 PRINT "Hello "; U$30 INPUT "How many stars do you want: ", N40 S$ = ""50 FOR I = 1 TO N60 S$ = S$ + "*"70 NEXT I80 PRINT S$90 INPUT "Do you want more stars? ", A$100 IF LEN(A$) = 0 THEN GOTO 90110 A$ = LEFT$(A$, 1)120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30130 PRINT "Goodbye "; U$140 END

10 INPUT "What is your name: ", U$20 PRINT "Hello "; U$30 INPUT "How many stars do you want: ", N40 S$ = ""50 FOR I = 1 TO N60 S$ = S$ + "*"70 NEXT I80 PRINT S$90 INPUT "Do you want more stars? ", A$100 IF LEN(A$) = 0 THEN GOTO 90110 A$ = LEFT$(A$, 1)120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30130 PRINT "Goodbye "; U$140 END

BASIC — 1964

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

30

interactive programmingfor the masses

interactive programmingfor the masses

JCL — 1964

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

31

//IS198CPY JOB (IS198T30500),'COPY JOB',CLASS=L,MSGCLASS=X//COPY01 EXEC PGM=IEBGENER//SYSPRINT DD SYSOUT=*//SYSUT1 DD DSN=OLDFILE,DISP=SHR//SYSUT2 DD DSN=NEWFILE,// DISP=(NEW,CATLG,DELETE),// SPACE=(CYL,(40,5),RLSE),// DCB=(LRECL=115,BLKSIZE=1150)//SYSIN DD DUMMY

//IS198CPY JOB (IS198T30500),'COPY JOB',CLASS=L,MSGCLASS=X//COPY01 EXEC PGM=IEBGENER//SYSPRINT DD SYSOUT=*//SYSUT1 DD DSN=OLDFILE,DISP=SHR//SYSUT2 DD DSN=NEWFILE,// DISP=(NEW,CATLG,DELETE),// SPACE=(CYL,(40,5),RLSE),// DCB=(LRECL=115,BLKSIZE=1150)//SYSIN DD DUMMY

invented scripting for IBM 360invented scripting for IBM 360

Semaphores — 1965

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

32

P — acquire resource… critical sectionV — release resource

P — acquire resource… critical sectionV — release resource

radically simplified concurrency controlradically simplified concurrency control

Planner — 1969Prolog — 1972

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

33

man(socrates).mortal(X) :- man(X).man(socrates).mortal(X) :- man(X).

Facts and rulesFacts and rules

?- mortal(socrates).Yes?- mortal(socrates).Yes

Queries and inferencesQueries and inferences ?- mortal(elvis).No?- mortal(elvis).No

Pascal — 1970

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

34

Supports structured programmingSupports structured programming

Successful with PCsSuccessful with PCs

function gcd (a, b: integer) : result real; var x : integer;begin if b= 0 then gcd := a else begin x := a; while (x >= b) do begin x := x - b end; gcd := gcd(b,x) endend

function gcd (a, b: integer) : result real; var x : integer;begin if b= 0 then gcd := a else begin x := a; while (x >= b) do begin x := x - b end; gcd := gcd(b,x) endend

begin

begin

end

endend

begin

C — 1972

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

35

Good for portable systems programmingGood for portable systems programming

Bridging low- and high-level programmingBridging low- and high-level programming

#include <stdio.h>//echo the command line argumentsint main (int argc, char* argv[]) {

int i;for (i=1; i<argc; i++) {

printf("%s ", argv[i]);}printf("\n");return 0;

}

#include <stdio.h>//echo the command line argumentsint main (int argc, char* argv[]) {

int i;for (i=1; i<argc; i++) {

printf("%s ", argv[i]);}printf("\n");return 0;

}

char*

i++

Smalltalk — 1972

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

36

Integer»factorialself = 0 ifTrue: [^ 1].self > 0 ifTrue: [^ self * (self - 1) factorial].self error: 'Not valid for negative integers'

Integer»factorialself = 0 ifTrue: [^ 1].self > 0 ifTrue: [^ self * (self - 1) factorial].self error: 'Not valid for negative integers'

5 factorial 1205 factorial 120

Everything is an objectEverything is an object

Everything happens by sending messagesEverything happens by sending messages

“Dynabook” vision“Dynabook” vision

self = 0 ifTrue: [^ 1]self > 0 ifTrue: [^ self * (self - 1) factorial].

ML polymorphic type inference — 1973

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

37

length [ ] = 0length (x:xs) = 1 + length xs

length :: [a] -> Int

length "hello" 5length [10..20] 11

length [ ] = 0length (x:xs) = 1 + length xs

length :: [a] -> Int

length "hello" 5length [10..20] 11

generic functions may be applied to many types of arguments

generic functions may be applied to many types of arguments

Monitors — 1974

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

38

structured concurrency controlstructured concurrency control

public class Account {protected int assets = 0;...public synchronized void withdraw(int amount) {

while (amount > assets) {try {

wait();} catch(InterruptedException e) { }

}assets -= amount;

}...

}

public class Account {protected int assets = 0;...public synchronized void withdraw(int amount) {

while (amount > assets) {try {

wait();} catch(InterruptedException e) { }

}assets -= amount;

}...

}

Bourne shell — 1977

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

39

cat Notes.txt| tr -c '[:alpha:]' '\012'| sed '/^$/d’| sort| uniq –c| sort –rn| head -5

cat Notes.txt| tr -c '[:alpha:]' '\012'| sed '/^$/d’| sort| uniq –c| sort –rn| head -5

Scripting pipelines of commands

Scripting pipelines of commands

14 programming14 languages 9 of 7 for 5 the

14 programming14 languages 9 of 7 for 5 the

SQL— 1978

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

40

SELECT * FROM BookWHERE price > 100.00ORDER BY title;

SELECT * FROM BookWHERE price > 100.00ORDER BY title;

Domain-specific language for relational databasesDomain-specific language for relational databases

Miranda — 1985

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

41

fibs = 1 : 1 : fibsAfter 1 1fibsAfter a b = (a+b) : fibsAfter b (a+b)fibs = 1 : 1 : fibsAfter 1 1fibsAfter a b = (a+b) : fibsAfter b (a+b)

Lazy evaluationLazy evaluation

take 10 fibs [1,1,2,3,5,8,13,21,34,55]take 10 fibs [1,1,2,3,5,8,13,21,34,55]

“Pure” functional programming“Pure” functional programming

Perl — 1987CGI — 1993

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

42

Text manipulation, then web scriptingText manipulation, then web scripting

#!/usr/bin/perl -wprint "Content-type: text/html\n\n";print <<'eof'<html><head><title>Directory contents</title></head><body><h1>Directory contents</h1><ul>eof;@files = <*>;foreach $file (@files) {

print '<li><a href="' . $file . '">' . $file . "</li>\n";}print "</ul></body></html>\n";__END__

#!/usr/bin/perl -wprint "Content-type: text/html\n\n";print <<'eof'<html><head><title>Directory contents</title></head><body><h1>Directory contents</h1><ul>eof;@files = <*>;foreach $file (@files) {

print '<li><a href="' . $file . '">' . $file . "</li>\n";}print "</ul></body></html>\n";__END__

@files = <*>;foreach $file (@files) {

print '<li><a href="' . $file . '">' . $file . "</li>\n";}

JavaScript — 1995AJAX — 2005

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

43

Client-side browser scriptingClient-side browser scripting

© Oscar Nierstrasz 44

Roadmap

> What is a programming language?> Programming = modeling> Evolution> Trends and Challenges

Programming Languages, Paradigms and Technology

Components, Frameworks, Patterns — 1990s

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

45

So far, limited impact on programming languages …So far, limited impact on programming languages …

Model-Driven Development — 1980s, 1990s

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

46

softwaredeveloper

PlatformIndependentModel

automatictranslation

Trends and Challenges

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

47

Bridging gap between users and technologyBridging gap between users and technologyyahoo pipesyahoo pipes

naked objectsnaked objects

subtextsubtext

graph transformationgraph transformation

Conclusions

© Oscar Nierstrasz

Programming Languages, Paradigms and Technology

48

Programming languages are for humans not just computersProgramming languages are for humans not just computers

Programming is modelingProgramming is modeling

Programming languages have always evolved to bring programming closer to the users’ problemsProgramming languages have always evolved to bring programming closer to the users’ problems

We are still very early in the history of programmingWe are still very early in the history of programming