Programming Paradigms - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Programming Paradigms

Description:

Text defn: 'a model or mental framework for representing or thinking about something' ... The Object-Oriented Programming Paradigm ... – PowerPoint PPT presentation

Number of Views:194
Avg rating:3.0/5.0
Slides: 25
Provided by: webhome2
Category:

less

Transcript and Presenter's Notes

Title: Programming Paradigms


1
Programming Paradigms
2
A Question....
  • What is your favourite programming language and
    why?

3
Problem Solving
  • Is there always only one way to think about a
    problem?
  • Lateral thinking
  • Sometimes a solution that is difficult to see
    becomes obvious when we think about the problem
    differently
  • Are there different ways of thinking about
    programming?

4
Paradigms
  • What is a paradigm?
  • Thomas S. Kuhn The Structure of Scientific
    Revolutions
  • Text defn a model or mental framework for
    representing or thinking about something

5
Paradigms (cont)
  • A paradigm offers a particular way of approaching
    an idea
  • It embodies certain assumptions about what is and
    is not possible
  • It entails what are the appropriate questions to
    ask about the subject at hand

6
Programming Paradigms
  • Offer different ways of approaching programming
    problems
  • Do we think of a problem in terms of
  • Functions?
  • Accessing memory locations?
  • Objects?
  • Logical assertions?

7
But First...
  • To explore each paradigm, we will solve the same
    problem in different ways
  • The problem we will use is the GCD or greatest
    common divisor problem
  • The GCD of two numbers u and v is the largest
    number which divides u and v evenly

8
The GCD Problem
  • The GCD of two numbers u and v is
  • The gcd of u and v is u if v 0
  • If v ! 0, then the gcd of u and v is the gcd of
    v and u modulus v

9
The Imperative/Procedural Paradigm
  • Largely based upon the Von Neumann model of
    computation
  • Sequential execution of instructions
  • Use of variables to represent memory locations
  • Use of assignment to change the values of
    variables

10
The Imperative/Procedural Paradigm (cont)
  • Computation is described as a sequence of
    instructions
  • Primary feature is a sequence of statements which
    represent commands or imperatives

11
The Object-Oriented Programming Paradigm
  • Somewhat of an extension or refinement of the
    procedural paradigm
  • Fundamental unit of computation is the object

12
The Object-Oriented Programming Paradigm
  • Each object has a set of properties associated
    with it
  • Ex size, height, colour
  • Each object also has a set of operations or
    methods associated with it.
  • Ex walk, talk, speak, draw

13
The Object-Oriented Programming Paradigm
  • Computation by message passing between objects
  • Essentially computers in the small
  • Primary goal to create reusable software
    components

14
The PIE of OOP
  • In the words of Homer Simpson Mmmm, pie....
  • Not the same thing....

15
The PIE of OOP
  • Polymorphism from the Greek for many forms
  • Inheritance allows us to define objects in
    terms of parent objects
  • Encapsulation each object is self-contained

16
The Functional Programming Paradigm
  • A much different approach to programming
  • Basic unit of computation is the function
  • Thus our program is just the repeated application
    of functions to known data.
  • Benefit much easier to reason about our programs
    (no side effects)

17
The Functional Programming Paradigm
  • Typically
  • No loops (recursion is heavily used instead)
  • No variables (only bindings)

18
A Side Note About Side Effects
  • When a function changes its external environment
    as a result of evaluating itself
  • Ex
  • Modification of a global variable
  • Output

19
Referential Transparency
  • A key concept in functional programming
  • Essentially means a function will always return
    the same value given the same arguments
  • Or more succinctly NO SIDE EFFECTS

20
Functions Are First Class Values
  • Can pass functions as arguments to other
    functions.
  • Sometimes called higher order programming or
    higher order functions

21
The Logic Programming Paradigm
  • A COMPLETELY different approach to programming
  • Rather than specify how a problem is to be
    solved, we describe what a solution will look
    like and let the inference engine figure out how
    to solve the problem

22
The Logic Programming Paradigm
  • As a result, sometimes called declarative
    programming (as opposed to imperative)
  • Fundamental units of computation are facts and
    clauses (or rules).
  • The inference engine uses formal logic to find
    solutions to our problems

23
The GCD Problem
  • The GCD of two numbers u and v is
  • The gcd of u and v is u if v 0
  • The gcd of u and v is x if v ! 0 and y is u
    modulus v and x is the gcd of v and y

24
A Big Question...
  • How do we select the best paradigm for the
    problem at hand, a priori (beforehand)?
  • Rules of thumb
  • Mathematical problem gt functional programming
  • Modeling gt OOP
Write a Comment
User Comments (0)
About PowerShow.com