paradigms
play

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"


  1. 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" (what is important, perspective to programming) 28

  2. Paradigms Division 1: Division 2: ● Imperative (two ways ● Imperative (procedural) – procedural ● Object oriented of – object oriented ● Functional classifying) – distributed (parallel) ● Logical ● Declarative ● Generative – functiona ● Script – logical – data base languages ● Model of programming – sequential – parallel 29

  3. ● Imperative/procedural paradigm ● destructive assignment, explicit control structures, e.g. C, Ada Examples ● Object oriented paradigm (object languages) of ● objects, creating objects, message passing, paradigms 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 30

  4. Why paradigm shift now? 31

  5. ● Real CPUs very complex ● Performance difficult to predict Why paradigm ● Concurrency/parallelism complicates shift now? things ● Programming more abstract, detached from hardware ● Compilers need more freedom to optimize code ● → Programmer cannot be in 100% control 32

  6. ● Functional and Logic programming ● Problems in imperative programming: Declarative Programming – Implementing algorithms • How to solve a problem • Tied to a specific computational model (abstract view of the real computer) Programmer: what needs • Forces a specific way of thinking to be done • Limiting compiler's/interpreter's Language: how it is done freedom (to optomize) – Problem definition needs its own formalism 33

  7. ● Mutual exclusion ● Aliasing Problems with ● Cache/data coherence imperative ● Instruction reordering paradigm ● (Distributed programs and time ordering) 34

  8. ● (Based on theory of functions in mathematics) Functional ● Principles Programming – expression (function call) value depends only 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 35

  9. ● Declarative "tells" something, imperative "orders" something Imperative ● Declaration: vs. int f(int i) { return 2*i; } declarative ● A sequence of statements (commands): ++i; i = f(i); cout << i; ● Is this a declaration or a statement?: int j = f(i); 36

  10. ● Gives more freedom to the compiler (optimization) Benefits of ● Makes data flow in program clearer functional (only parameters & return value) programming ● 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(?) 37

  11. ● No side effects, no mutable data ● → sharing data between threads ok Concurrency ● More freedom in execution order ● → automatic parallelization easier ● Synchronization and exchanging information between threads more challenging ● Transactional memory one promising route 38

  12. ● Initially "strange" for those used to imperative programming Problems ● Performance sometimes difficult to with predict (exact execution steps not functional clear, especially with laziness) programming ● Interaction with outside world not as simple as in imperative programming 39

  13. ● Claims to produce less errors, because forces programmers to think Other claims more about ● Claims to encourage programmers to functional structure their code better programming 40

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend