Computational situation involves at least three different types of entities
a program - a thing that might be edited within a text editor
the process or computation to which the program gives rise, upon being executed
domain or subject matter that the computation is about
Computation provides framework for «HOW TO» not «What IS
We will study Computational Process
choice
practice
vocabulary
speed of learning
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.
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
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
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
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
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
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.