Introduction

  • Computer languages are not just a way to get a computer to perform operations
  • Computer languages are a novel formal medium for expressing ideas about methodology
    • programs are and must be for people to read
    • only incidental for machines to execute
    • Important to understand techniques to control intellectual complexity of large software systems
      • not just syntax
      • not just programming language constructs
      • not just clever algorithms
      • not just analysis

Computation

  • Computational situation involves at least three different types of entities
    1. a program - a thing that might be edited within a text editor
    2. the process or computation to which the program gives rise, upon being executed
    3. domain or subject matter that the computation is about
  • Computation provides framework for «HOW TO» not «What IS
    • e.g. not declarations
  • We will study Computational Process
    • abstract things that inhabit computers
    • spells
    • you must anticipate outcome and consequences

Why learn programming?

  • choice
  • practice
  • vocabulary
  • speed of learning

Attributes of a best programming language

  • readability
  • performance
  • portability
  • writability
  • naturalness for applications
  • environment
  • verification

Main difference between object-oriented and functional programming

The thing that differs object-oriented programming from functional programming is »=». Assignment operator! There is no assignment operator in Scheme.

Example:

acct.getBalance();

Nobody knows what that line will produce, it gives different output every time depending on the condition of object etc. In functional programming a line give the same output all the time.

Language Paradigms

Imperative or Procedural Programming

  • Model follows from hardware
  • Command drive or statement oriented
  • Basic concept is machine state
  • Program is sequence of statements
  • Execution changes value of one or more locations in memory (new state)
  • Syntax
  • C, Pascal, Cobol

Applicative or Functional Programming

  • Look at functions the program represents rather than its state changes
  • Look at results rather than available data
  • Focus on the following:

What is the function that must be applied to the initial machine state by accessing the initial set of variables and combining them in specific ways in order to get an answer

  • Use primitive functions to build more complex ones
  • Consider functional transformations
  • fn ( .. fn( .. (fn (data)))
  • Lisp, ML, Scheme
  • Assignment free programming

Rule-based or Logic Programming

  • Execute by checking for presence of certain enabling conditions and when satisfied execute appropriate actions
  • Syntax (condition → action)
  • Enabling conditions determine execution order
  • Like set of filters applied to data
  • Prolog

Object-Oriented Programming

  • Complex data objects with limited set of functions
  • Complex objects build from simple ones
  • Important concepts
    • encapsulation
    • inheritance
    • polymorphism
  • Combination of imperative and functional programming
  • C++, Smalltalk, Java

Access-Oriented Programming

  • Attaches side effects or demons to variables so that certain functions will be performed as variables are manipulated

Constraint Programming

  • Like logic programming
  • More declarative than imperative
  • Programmer specifies constraints that must always be maintained during execution (e.g. window should always be 2 * height)
  • Underlying constraint satisfaction mechanism

Visitor Pattern

The code below is pseudo-code.

process (transaction transmission){
      transaction.process (this);
}

Instead of making several if-statements or case-statements for all kinds of transactions, Visitor Pattern says it's easier to let the transaction process itself. Client of a bank asking the bank account to process the transaction, bank account dispatches the transaction, transaction gives the result back, and client gets it from bank account.

 
programming_paradigms/introduction.txt · Последние изменения: 2009/09/17 04:21 От freetonik
 
За исключением случаев, когда указано иное, содержимое этой вики предоставляется на условиях следующей лицензии:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki