Programming
Waging War on Complexity
Waging War on Complexity
Waging War on Complexity
SPA 2006
Types of complexity
• Sources of complexity
• Part 2: Functional Relational Programming
Worked Example
Development
Ben Moseley & Peter Marks SPA 2006
Accidents and Essence
• State
Control
• Code Volume
Expression
X
while ((l < h) && (a[l] <= p))
l = l+1; Arbitrary order
while ((h > l) && (a[h] >= p))
h = h-1;
if (l < h) {
Transient state
t = a[l];
a[l] = a[h];
Duplication
a[h] = t;
}
} while (l < h); Specific algorithm
•Control
When is order unimportant?
•Expression
•Duplication or redundancy
•Inconsistency (particularly of idiom)
•Missing abstraction
•Unnecessary abstraction
Platform
• Language
Worked Example
• Exercise & Discussion
Accidental Essential
Accident
Essential
al
Infrastructure
o
bj o
bj o
bj
o
...NO!!
bj
Immutability
Accident Essential
al
Infrastructure
Accident Essential
al Logic
State &
Control
Essential
State
Infrastructure
FRP
n
se
se Architecture
t
nti
Infras
nti
tructu
aal
alre
lc
Logi
Stat
Ste
at
e
& Interfaces
Co
nt
rol
Relations
Function
Ben Moseley & Peter Marks SPA 2006
s
Essential
dent
Logic
Essential
al
State
Stat
e&
Cont
rol
Infrastructure
Lifecycle
Lifecycle
Under
Proposed Rejected
Review
Awaiting Accepted
Correction
s
Publishe
(“State” Transition Diagram)
d
Ben Moseley & Peter Marks SPA 2006
Essential
Accidenta
Logic
Essential State
l
State &
Essential
Control
State
Infrastructure
Example
Essential
Control
State
Infrastructure
PAPER OPINION
paper autho submitte paper reviewer opinion
DB Theory r
ian d
21/05/06 DB Theory adam GOOD
Pi Calculus sam 03/05/06 DB Theory fred BAD
OODBs tim 17/06/06 Pi Calculus adam GOOD
Ruby On
bob 12/11/06 Pi Calculus fred GOOD
Rails
Pi Calculus simon GOOD
Ruby On
adam GOOD
RailsOn
Ruby
POSTING fred GOOD
RailsOn
Ruby
paper posted simon GOOD
Rails
DB Theory 23/05/06 JOURNAL
Pi Calculus 05/05/06 issue paper
Ruby On Rails 15/11/06
17 Pi Calculus
18 Ruby On Rails
Essential Logic
l
State &
Essential
Control
State
Infrastructure
Essential Logic
l
State &
Essential
Control
State
Infrastructure
• Integrity Constraints
• Not concerned with State at all (eg
provides no facilities for manipulating
State)
Essential
State
Example Infrastructure
OPINION
OVERVIEW paper reviewer opinion
paper opinion DB Theory adam GOOD
DB Theory GOOD DB Theory fred BAD
DB Theory BAD Pi Calculus adam GOOD
Pi Calculus GOOD Pi Calculus fred GOOD
Ruby On Pi Calculus simon GOOD
GOOD
Rails Ruby On
adam GOOD
RailsOn
Ruby
fred GOOD
RailsOn
Ruby
simon GOOD
Rails
Essential
State
Example Infrastructure
OPINION
BAD_OPINIONS paper reviewer opinion
paper reviewer opinion DB Theory adam GOOD
DB Theory fred BAD DB Theory fred BAD
Pi Calculus adam GOOD
Pi Calculus fred GOOD
Pi Calculus simon GOOD
Ruby On
adam GOOD
RailsOn
Ruby
fred GOOD
RailsOn
Ruby
simon GOOD
Rails
BAD_OPINIONS = restrict(OPINION |
opinion == BAD)
Ben Moseley & Peter Marks SPA 2006
Essential Logic Accidenta
l
State &
Control
Essential
Logic
Essential
State
Example Infrastructure
REJECTED BAD_OPINIONS
paper paper reviewer opinion
DB Theory DB Theory fred BAD
Essential
State
Example Infrastructure
OPINION
GOOD_OPINIONS paper reviewer opinion
paper reviewer opinion DB Theory adam GOOD
DB Theory adam GOOD DB Theory fred BAD
Pi Calculus adam GOOD Pi Calculus adam GOOD
Pi Calculus fred GOOD Pi Calculus fred GOOD
Pi Calculus simon GOOD Pi Calculus simon GOOD
Ruby On Ruby On
adam GOOD adam GOOD
RailsOn
Ruby RailsOn
Ruby
fred GOOD fred GOOD
RailsOn
Ruby RailsOn
Ruby
simon GOOD simon GOOD
Rails Rails
GOOD_OPINIONS = restrict(OPINION |
opinion == GOOD)
Ben Moseley & Peter Marks SPA 2006
Essential Logic Accidenta
l
State &
Control
Essential
Logic
Essential
State
Example Infrastructure
REJECTED
paper GOOD_OPINIONS
DB Theory paper reviewer opinion
DB Theory adam GOOD
ACCEPTED...
ACCEPTED Pi Calculus adam GOOD
paper Pi Calculus fred GOOD
DBCalculus
Theory Pi Calculus simon GOOD
Pi Ruby On
Ruby On adam GOOD
Pi Calculus RailsOn
Ruby
RailsOn
Ruby fred GOOD
RailsOn
Ruby
Rails simon GOOD
Rails
Essential Logic
l
State &
Essential
Control
State
Infrastructure
SCORE OPINION
paper reviewer score paper reviewe score opinion
DB Theory adam 98% DB Theory r
adam 98% GOOD
DB Theory fred 48% DB Theory fred 48% BAD
Pi Calculus adam 79% Pi Calculus adam 79% GOOD
Pi Calculus fred 73% Pi Calculus fred 73% GOOD
Pi Calculus simon 74% Pi Calculus simon 74% GOOD
Ruby On Ruby On
adam 83% adam 83% GOOD
RailsOn
Ruby RailsOn
Ruby
fred 89% fred 89% GOOD
RailsOn
Ruby RailsOn
Ruby
simon 77% simon 77% GOOD
Rails Rails
OPINION =
extend(SCORE,
opinion=opinionFromScore(score))
Ben Moseley & Peter Marks SPA 2006
Essential
Accidenta
Logic
Essential Logic
l
State &
Essential
Control
State
Infrastructure
• Comprised of:
• Derived Relations
• User-defined functions
• Constraints
• No State, no Control
Essential
State
Infrastructure
l
State &
Essential
Control
State
Infrastructure
SPA 2006