Paradigms following: 1. Model of computation 2. Concepts - - PowerPoint PPT Presentation

paradigms
SMART_READER_LITE
LIVE PREVIEW

Paradigms following: 1. Model of computation 2. Concepts - - PowerPoint PPT Presentation

Programming paradigm: An abstract concept that covers the Paradigms following: 1. Model of computation 2. Concepts (Primitives of the programming language) 3. Tools (data structures and algorithms) 4. The "human mindset"


slide-1
SLIDE 1

28

Paradigms

Programming paradigm: – An abstract concept that covers the following:

  • 1. Model of computation
  • 2. Concepts (Primitives of the

programming language)

  • 3. Tools (data structures and

algorithms)

  • 4. The "human mindset" (what is

important, perspective to programming)

slide-2
SLIDE 2

29

Paradigms (two ways

  • f

classifying)

  • Imperative (procedural)
  • Object oriented
  • Functional
  • Logical
  • Generative
  • Script
  • Model of programming

– sequential – parallel

Division 1: Division 2:

  • Imperative

– procedural – object oriented – distributed (parallel)

  • Declarative

– functiona – logical – data base languages

slide-3
SLIDE 3

30

Examples

  • f

paradigms

  • Imperative/procedural paradigm
  • destructive assignment, explicit control

structures, e.g. C, Ada

  • Object oriented paradigm (object languages)
  • objects, creating objects, message passing,

inheritance, e.g. Java, (C++)

  • Functional paradigm (functional languages)
  • immutable variables, no side-effects, e.g.

Haskell, Scala, Clojure

  • Logic paradigm
  • Facts & rules, automatic deduction of

results, e.g. Prolog, Curry

  • Parallel paradigm
  • processes, synchronisation, message

passing, e.g. Go, Erlang

slide-4
SLIDE 4

31

Why paradigm shift now?

slide-5
SLIDE 5

32

Why paradigm shift now?

  • Real CPUs very complex
  • Performance difficult to predict
  • Concurrency/parallelism complicates

things

  • Programming more abstract,

detached from hardware

  • Compilers need more freedom to
  • ptimize code
  • → Programmer cannot be in 100%

control

slide-6
SLIDE 6

33

Declarative Programming

  • Functional and Logic programming
  • Problems in imperative programming:

– Implementing algorithms

  • How to solve a problem
  • Tied to a specific computational model

(abstract view of the real computer)

  • Forces a specific way of thinking
  • Limiting compiler's/interpreter's

freedom (to optomize) – Problem definition needs its own formalism Programmer: what needs to be done Language: how it is done

slide-7
SLIDE 7

34

Problems with imperative paradigm

  • Mutual exclusion
  • Aliasing
  • Cache/data coherence
  • Instruction reordering
  • (Distributed programs and time
  • rdering)
slide-8
SLIDE 8

35

Functional Programming

  • (Based on theory of functions in

mathematics)

  • Principles

– expression (function call) value depends

  • nly on the values of subexpressions

(arguments) – No side effects – No assignment, immutable data – Functions as "first-class citizens", as data

  • Many functional programming languages

are ”impure” (contain assignments etc.) – Functional part is however dominating

slide-9
SLIDE 9

36

Imperative vs. declarative

  • Declarative "tells" something,

imperative "orders" something

  • Declaration:

int f(int i) { return 2*i; }

  • A sequence of statements

(commands):

++i; i = f(i); cout << i;

  • Is this a declaration or a statement?:

int j = f(i);

slide-10
SLIDE 10

37

Benefits of functional programming

  • Gives more freedom to the compiler

(optimization)

  • Makes data flow in program clearer

(only parameters & return value)

  • Make parallelization easier (immutable

data & clear data flow -> easier to add concurrency)

  • Forces programmer to think more

exactly(?)

  • Encourages programmers to structure

their code better(?)

slide-11
SLIDE 11

38

Concurrency

  • No side effects, no mutable data
  • → sharing data between threads ok
  • More freedom in execution order
  • → automatic parallelization easier
  • Synchronization and exchanging

information between threads more challenging

  • Transactional memory one promising

route

slide-12
SLIDE 12

39

Problems with functional programming

  • Initially "strange" for those used to

imperative programming

  • Performance sometimes difficult to

predict (exact execution steps not clear, especially with laziness)

  • Interaction with outside world not as

simple as in imperative programming

slide-13
SLIDE 13

40

Other claims about functional programming

  • Claims to produce less errors,

because forces programmers to think more

  • Claims to encourage programmers to

structure their code better