SlideShare uma empresa Scribd logo
1 de 158
Baixar para ler offline
Procedural Programming
It's Back? It Never Went Away
@KevlinHenney
Brycgstow
Bricstow
Bristow
Bristol
procedure
procedural
procedural?
µονόλιθος
This is the Unix philosophy:
Write programs that do one
thing and do it well.Write
programs to work together.
Doug McIlroy
µservices
In McIlroy's summary, the hard
part is his second sentence:
Write programs to work
together.
John D Cook
In the long run every
program becomes rococo
— then rubble.
Alan Perlis
1960s
1960s
I began to use the term “software
engineering” to distinguish it from
hardware and other kinds of engineering;
yet, treat each type of engineering as part of
the overall systems engineering process.
Margaret Hamilton
Define a subset of the system which is
small enough to bring to an operational
state [...] then build on that subsystem.
E E David
This strategy requires that the system
be designed in modules which can be
realized, tested, and modified
independently, apart from conventions
for intermodule communication.
E E David
The design process
is an iterative one.
Andy Kinslow
There are two classes of system designers.
The first, if given five problems will solve
them one at a time.
Andy Kinslow
The second will come back and announce
that these aren’t the real problems, and
will eventually propose a solution to the
single problem which underlies the
original five.
Andy Kinslow
This is the ‘system type’ who is great
during the initial stages of a design project.
However, you had better get rid of him
after the first six months if you want to get
a working system.
Andy Kinslow
A software system can best be
designed if the testing is interlaced
with the designing instead of
being used after the design.
Alan Perlis
proc is leap year = (int year) bool:
skip;
proc is leap year = (int year) bool:
false;
[] proposition leap year spec =
(
("Years not divisible by 4 are not leap years",
void: (assert (not is leap year (1967))))
);
mode proposition = struct (string name, proc void test);
proc is leap year = (int year) bool:
false;
[] proposition leap year spec =
(
("Years not divisible by 4 are not leap years",
void: (assert (not is leap year (1967))))
);
test (leap year spec)
mode proposition = struct (string name, proc void test);
proc test = ([] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
test of spec [entry];
print (new line)
od;
proc is leap year = (int year) bool:
year mod 4 = 0;
[] proposition leap year spec =
(
("Years not divisible by 4 are not leap years",
void: (assert (not is leap year (1967)))),
("Years divisible by 4 but not by 100 are leap years",
void: (assert (is leap year (1968))))
);
test (leap year spec)
proc is leap year = (int year) bool:
year mod 4 = 0 and year mod 100 /= 0;
[] proposition leap year spec =
(
("Years not divisible by 4 are not leap years",
void: (assert (not is leap year (1967)))),
("Years divisible by 4 but not by 100 are leap years",
void: (assert (is leap year (1968)))),
("Years divisible by 100 but not by 400 are not leap years",
void: (assert (not is leap year (1900))))
);
test (leap year spec)
proc is leap year = (int year) bool:
year mod 4 = 0 and year mod 100 /= 0 or year mod 400 = 0;
[] proposition leap year spec =
(
("Years not divisible by 4 are not leap years",
void: (assert (not is leap year (1967)))),
("Years divisible by 4 but not by 100 are leap years",
void: (assert (is leap year (1968)))),
("Years divisible by 100 but not by 400 are not leap years",
void: (assert (not is leap year (1900)))),
("Years divisible by 400 are leap years",
void: (assert (is leap year (2000))))
);
test (leap year spec)
proc is leap year = (int year) bool:
year mod 4 = 0 and year mod 100 /= 0 or year mod 400 = 0;
[] proposition leap year spec =
(
("Years not divisible by 4 are not leap years",
with (2018, 2001, 1967, 1), expect (false)),
("Years divisible by 4 but not by 100 are leap years",
with (2016, 1984, 1968, 4), expect (true)),
("Years divisible by 100 but not by 400 are not leap years",
with (2100, 1900, 100), expect (false)),
("Years divisible by 400 are leap years",
with (2000, 1600, 400), expect (true))
);
test (is leap year, leap year spec)
mode expect = bool;
mode with = flex [1:0] int;
mode proposition = struct (string name, with inputs, expect result);
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print (if report = "" then (new line) else (new line, report, new line) fi)
od;
proc test = (proc (int) bool function, [] proposition spec) void:
for entry from lwb spec to upb spec
do
print (name of spec [entry]);
string report := "", separator := " failed for ";
[] int inputs = inputs of spec [entry];
for value from lwb inputs to upb inputs
do
if
bool expected = result of spec [entry];
function (inputs [value]) /= expected
then
report +:= separator + whole(inputs[value], 0);
separator := " "
fi
od;
print ((report = "" | (new line) | (new line, report, new line)))
od;
We instituted a rigorous regression
test for all of the features of AWK.
Any of the three of us who put in a
new feature into the language [...],
first had to write a test for the new
feature.
Alfred Aho
http://www.computerworld.com.au/article/216844/a-z_programming_languages_awk/
There is no such question as testing things after the
fact with simulation models, but that in effect the
testing and the replacement of simulations with
modules that are deeper and more detailed goes on
with the simulation model controlling, as it were,
the place and order in which these things are done.
Alan Perlis
As design work progresses this
simulation will gradually evolve
into the real system.
The simulation is the design.
Tad B Pinkerton
goto
/ WordFriday
snowclone, noun
▪ clichéd wording used as a template, typically
originating in a single quote
▪ e.g., "X considered harmful", "These aren't
the Xs you're looking for", "X is the new Y",
"It's X, but not as we know it", "No X left
behind", "It's Xs all the way down", "All your
X are belong to us"
FUNCTION ISLEAP(YEAR)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) GOTO 20
IF (MOD(YEAR, 100) .EQ. 0) GOTO 10
IF (MOD(YEAR, 4) .EQ. 0) GOTO 20
10 ISLEAP = .FALSE.
RETURN
20 ISLEAP = .TRUE.
END
FUNCTION ISLEAP(YEAR)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) GOTO 20
IF (MOD(YEAR, 100) .EQ. 0) GOTO 10
IF (MOD(YEAR, 4) .EQ. 0) GOTO 20
10 ISLEAP = .FALSE.
RETURN
20 ISLEAP = .TRUE.
RETURN
END
FUNCTION ISLEAP(YEAR)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) GOTO 20
IF (MOD(YEAR, 100) .EQ. 0) GOTO 10
IF (MOD(YEAR, 4) .EQ. 0) GOTO 20
10 ISLEAP = .FALSE.
GOTO 30
20 ISLEAP = .TRUE.
30 RETURN
END
FUNCTION ISLEAP(YEAR)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) GOTO 20
IF (MOD(YEAR, 100) .EQ. 0) GOTO 10
IF (MOD(YEAR, 4) .EQ. 0) GOTO 20
10 ISLEAP = .FALSE.
GOTO 30
20 ISLEAP = .TRUE.
GOTO 30
30 RETURN
END
FUNCTION ISLEAP(YEAR)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) GOTO 20
IF (MOD(YEAR, 100) .EQ. 0) GOTO 10
IF (MOD(YEAR, 4) .EQ. 0) GOTO 20
10 ISLEAP = .FALSE.
GOTO 30
20 ISLEAP = .TRUE.
GOTO 30
30 CONTINUE
RETURN
END
FUNCTION ISLEAP(Year)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) THEN
ISLEAP = .TRUE.
ELSE IF (MOD(YEAR, 100) .EQ. 0) THEN
ISLEAP = .FALSE.
ELSE IF (MOD(YEAR, 4) .EQ. 0) THEN
ISLEAP = .TRUE.
ELSE
ISLEAP = .FALSE.
END IF
END
FUNCTION ISLEAP(Year)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) THEN
ISLEAP = .TRUE.
ELSE IF (MOD(YEAR, 100) .EQ. 0) THEN
ISLEAP = .FALSE.
ELSE IF (MOD(YEAR, 4) .EQ. 0) THEN
ISLEAP = .TRUE.
ELSE
ISLEAP = .FALSE.
END IF
END
A goto completely
invalidates the high-level
structure of the code.
Taligent's Guide to Designing Programs
FUNCTION ISLEAP(YEAR)
LOGICAL ISLEAP
INTEGER YEAR
IF (MOD(YEAR, 400) .EQ. 0) GOTO 20
IF (MOD(YEAR, 100) .EQ. 0) GOTO 10
IF (MOD(YEAR, 4) .EQ. 0) GOTO 20
10 ISLEAP = .FALSE.
RETURN
20 ISLEAP = .TRUE.
END
send(to, from, count)
register short *to, *from;
register count;
{
register n=(count+7)/8;
switch(count%8){
case 0: do{ *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
}while(--n>0);
}
}
send(to, from, count)
register short *to, *from;
register count;
{
register n=(count+7)/8;
switch(count%8){
case 0: do{ *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
}while(--n>0);
}
}
I feel a combination of
pride and revulsion at
this discovery.
Tom Duff
send(to, from, count)
register short *to, *from;
register count;
{
register n=(count+7)/8;
switch(count%8){
case 0: do{ *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
}while(--n>0);
}
}
Many people have said that the worst
feature of C is that switches don't break
automatically before each case label.
This code forms some sort of argument
in that debate, but I'm not sure whether
it's for or against.
Tom Duff
break
Plankalkül
Bram Bruines
continue
break
return
One of the most powerful
mechanisms for program
structuring [...] is the block
and procedure concept.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
sequence
selection
iteration
Main Program and Subroutine
The goal is to decompose a program into
smaller pieces to help achieve modifiability.
A program is decomposed hierarchically.
Len Bass, Paul Clements & Rick Kazman
Software Architecture in Practice
afferent branch transform branch efferent branch
main
subroutine subroutine
subroutine
subroutine
subroutine
subroutine
subroutine
subroutine
There is typically a single thread of control
and each component in the hierarchy gets
this control (optionally along with some
data) from its parent and passes it along
to its children.
Len Bass, Paul Clements & Rick Kazman
Software Architecture in Practice
afferent branch transform branch efferent branch
main
subroutine subroutine
subroutine
subroutine
subroutine
subroutine
subroutine
subroutine
afferent branch transform branch efferent branch
main
procedure procedure
procedure
procedure
procedure
procedure
procedure
procedure
afferent branch transform branch efferent branch
main
function function
function
function
function
function
function
function
main
function function
function
function
function
function
function
function
You cannot teach beginners
top-down programming,
because they don't know
which end is up.
C A R Hoare
Everything should be built
top-down, except the first
time.
Alan Perlis
Hamlet: To be, or not to be,
that is the question.
Ophelia: 'Tis in my memory
locked, and you yourself
shall keep the key of it.
Hamlet: Yea, from the table
of my memory I'll wipe
away all trivial fond records.
One of the most powerful
mechanisms for program
structuring [...] is the block
and procedure concept.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
begin
ref(Book) array books(1:capacity);
integer count;
procedure Push(top); ...
procedure Pop; ...
boolean procedure IsEmpty; ...
boolean procedure IsFull; ...
integer procedure Depth; ...
ref(Book) procedure Top; ...
count := 0
end;
A procedure which is capable of
giving rise to block instances which
survive its call will be known as a
class; and the instances will be
known as objects of that class.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
class Stack(capacity);
integer capacity;
begin
ref(Book) array books(1:capacity);
integer count;
procedure Push(top); ...
procedure Pop; ...
boolean procedure IsEmpty; ...
boolean procedure IsFull; ...
integer procedure Depth; ...
ref(Book) procedure Top; ...
count := 0
end;
const newStack = () => {
const items = []
return {
depth: () => items.length,
top: () => items[0],
pop: () => { items.shift() },
push: newTop => { items.unshift(newTop) },
}
}
const newStack = () => {
const items = []
return {
depth: () => items.length,
top: () => items[items.length - 1],
pop: () => { items.pop() },
push: newTop => { items.push(newTop) },
}
}
Concatenation is an operation
defined between two classes A
and B, or a class A and a block C,
and results in the formation of a
new class or block.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
Concatenation consists in a
merging of the attributes of both
components, and the composition
of their actions.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
const stackable = base => {
const items = []
return Object.assign(base, {
depth: () => items.length,
top: () => items[items.length - 1],
pop: () => { items.pop() },
push: newTop => { items.push(newTop) },
})
}
const newStack = () => stackable({})
const clearable = base => {
return Object.assign(base, {
clear: () => {
while (base.depth())
base.pop()
},
})
}
const newStack =
() => clearable(stackable({}))
const newStack =
() => compose(clearable, stackable)({})
const compose = (...funcs) =>
arg => funcs.reduceRight(
(composed, func) => func(composed), arg)
Concept Hierarchies
The construction principle involved is best
called abstraction; we concentrate on features
common to many phenomena, and we abstract
away features too far removed from the
conceptual level at which we are working.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
A type hierarchy is composed of subtypes and
supertypes. The intuitive idea of a subtype is
one whose objects provide all the behavior of
objects of another type (the supertype) plus
something extra.
Barbara Liskov
"Data Abstraction and Hierarchy"
What is wanted here is something like the
following substitution property: If for each
object o1 of type S there is an object o2 of type
T such that for all programs P defined in terms
of T, the behavior of P is unchanged when o1 is
substituted for o2, then S is a subtype of T.
Barbara Liskov
"Data Abstraction and Hierarchy"
const nonDuplicateTop = base => {
const push = base.push
return Object.assign(base, {
push: newTop => {
if (base.top() !== newTop)
push(newTop)
},
})
}
tests = {
...
'A non-empty stack becomes deeper by retaining a pushed item as its top':
() => {
const stack = newStack()
stack.push('ACCU')
stack.push('2018')
stack.push('2018')
assert(stack.depth() === 3)
assert(stack.top() === '2018')
},
...
}
const newStack =
() => compose(clearable, stackable)({})
tests = {
...
'A non-empty stack becomes deeper by retaining a pushed item as its top':
() => {
const stack = newStack()
stack.push('ACCU')
stack.push('2018')
stack.push('2018')
assert(stack.depth() === 3)
assert(stack.top() === '2018')
},
...
}
const newStack =
() => compose(nonDuplicateTop, clearable, stackable)({})
tests = {
...
'A non-empty stack becomes deeper by retaining a pushed item as its top':
() => {
const stack = newStack()
stack.push('ACCU')
stack.push('2018')
stack.push('2018')
assert(stack.depth() === 3)
assert(stack.top() === '2018')
},
...
}
What is wanted here is something like the
following substitution property: If for each
object o1 of type S there is an object o2 of type
T such that for all programs P defined in terms
of T, the behavior of P is unchanged when o1 is
substituted for o2, then S is a subtype of T.
Barbara Liskov
"Data Abstraction and Hierarchy"
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
The Synchronisation Quadrant
Procedural Comfort Zone
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
Procedural Discomfort Zone
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
Procedural Comfort Zone
Threads and locks —
they’re kind of a dead
end, right?
BretVictor
"The future of programming"
So, I think if [...] we’re still using
threads and locks, we should
just, like, pack up and go home,
’cause we’ve clearly failed as an
engineering field.
BretVictor
"The future of programming"
Procedural Comfort Zone
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
single-threaded activity
no shared mutable state
coordination
N
bounded
buffered
asynchronous
N =
unbounded
buffered
asynchronous
∞
N = 1
bounded
buffered
asynchronous
futurepromise
N = 0
bounded
unbuffered
synchronous
Toutes choses sont dites
déjà; mais comme
personne n'écoute, il faut
toujours recommencer.
André Gide
Everything has been said
before; but since nobody
listens, we must always
start again.
André Gide

Mais conteúdo relacionado

Mais procurados

Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
Bryan O'Sullivan
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
Bryan O'Sullivan
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
stasimus
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
Bryan O'Sullivan
 

Mais procurados (20)

Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
Lezione03
Lezione03Lezione03
Lezione03
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Java Generics for Dummies
Java Generics for DummiesJava Generics for Dummies
Java Generics for Dummies
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
Monad Transformers - Part 1
Monad Transformers - Part 1Monad Transformers - Part 1
Monad Transformers - Part 1
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
C# quick ref (bruce 2016)
C# quick ref (bruce 2016)C# quick ref (bruce 2016)
C# quick ref (bruce 2016)
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 

Semelhante a Procedural Programming: It’s Back? It Never Went Away

The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
arihantsherwani
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
Naveen Kumar
 

Semelhante a Procedural Programming: It’s Back? It Never Went Away (20)

JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languages
 
SNP STEAM Academy 2017 Class #12
SNP STEAM Academy 2017 Class #12SNP STEAM Academy 2017 Class #12
SNP STEAM Academy 2017 Class #12
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScript
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
Kpi driven-java-development-fn conf
Kpi driven-java-development-fn confKpi driven-java-development-fn conf
Kpi driven-java-development-fn conf
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
 
Headache from using mathematical software
Headache from using mathematical softwareHeadache from using mathematical software
Headache from using mathematical software
 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
 

Mais de Kevlin Henney

Mais de Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID Deconstruction
 
Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that Word
 

Último

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

Procedural Programming: It’s Back? It Never Went Away

  • 1. Procedural Programming It's Back? It Never Went Away @KevlinHenney
  • 9.
  • 11.
  • 12. This is the Unix philosophy: Write programs that do one thing and do it well.Write programs to work together. Doug McIlroy
  • 14. In McIlroy's summary, the hard part is his second sentence: Write programs to work together. John D Cook
  • 15.
  • 16. In the long run every program becomes rococo — then rubble. Alan Perlis
  • 17. 1960s
  • 18. 1960s
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. I began to use the term “software engineering” to distinguish it from hardware and other kinds of engineering; yet, treat each type of engineering as part of the overall systems engineering process. Margaret Hamilton
  • 25.
  • 26.
  • 27. Define a subset of the system which is small enough to bring to an operational state [...] then build on that subsystem. E E David
  • 28. This strategy requires that the system be designed in modules which can be realized, tested, and modified independently, apart from conventions for intermodule communication. E E David
  • 29. The design process is an iterative one. Andy Kinslow
  • 30. There are two classes of system designers. The first, if given five problems will solve them one at a time. Andy Kinslow
  • 31. The second will come back and announce that these aren’t the real problems, and will eventually propose a solution to the single problem which underlies the original five. Andy Kinslow
  • 32. This is the ‘system type’ who is great during the initial stages of a design project. However, you had better get rid of him after the first six months if you want to get a working system. Andy Kinslow
  • 33. A software system can best be designed if the testing is interlaced with the designing instead of being used after the design. Alan Perlis
  • 34. proc is leap year = (int year) bool: skip;
  • 35.
  • 36.
  • 37. proc is leap year = (int year) bool: false; [] proposition leap year spec = ( ("Years not divisible by 4 are not leap years", void: (assert (not is leap year (1967)))) );
  • 38. mode proposition = struct (string name, proc void test);
  • 39. proc is leap year = (int year) bool: false; [] proposition leap year spec = ( ("Years not divisible by 4 are not leap years", void: (assert (not is leap year (1967)))) ); test (leap year spec)
  • 40. mode proposition = struct (string name, proc void test); proc test = ([] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); test of spec [entry]; print (new line) od;
  • 41. proc is leap year = (int year) bool: year mod 4 = 0; [] proposition leap year spec = ( ("Years not divisible by 4 are not leap years", void: (assert (not is leap year (1967)))), ("Years divisible by 4 but not by 100 are leap years", void: (assert (is leap year (1968)))) ); test (leap year spec)
  • 42. proc is leap year = (int year) bool: year mod 4 = 0 and year mod 100 /= 0; [] proposition leap year spec = ( ("Years not divisible by 4 are not leap years", void: (assert (not is leap year (1967)))), ("Years divisible by 4 but not by 100 are leap years", void: (assert (is leap year (1968)))), ("Years divisible by 100 but not by 400 are not leap years", void: (assert (not is leap year (1900)))) ); test (leap year spec)
  • 43. proc is leap year = (int year) bool: year mod 4 = 0 and year mod 100 /= 0 or year mod 400 = 0; [] proposition leap year spec = ( ("Years not divisible by 4 are not leap years", void: (assert (not is leap year (1967)))), ("Years divisible by 4 but not by 100 are leap years", void: (assert (is leap year (1968)))), ("Years divisible by 100 but not by 400 are not leap years", void: (assert (not is leap year (1900)))), ("Years divisible by 400 are leap years", void: (assert (is leap year (2000)))) ); test (leap year spec)
  • 44.
  • 45. proc is leap year = (int year) bool: year mod 4 = 0 and year mod 100 /= 0 or year mod 400 = 0; [] proposition leap year spec = ( ("Years not divisible by 4 are not leap years", with (2018, 2001, 1967, 1), expect (false)), ("Years divisible by 4 but not by 100 are leap years", with (2016, 1984, 1968, 4), expect (true)), ("Years divisible by 100 but not by 400 are not leap years", with (2100, 1900, 100), expect (false)), ("Years divisible by 400 are leap years", with (2000, 1600, 400), expect (true)) ); test (is leap year, leap year spec)
  • 46. mode expect = bool; mode with = flex [1:0] int; mode proposition = struct (string name, with inputs, expect result);
  • 47. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 48. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 49. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 50. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 51. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 52. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 53. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print (if report = "" then (new line) else (new line, report, new line) fi) od;
  • 54. proc test = (proc (int) bool function, [] proposition spec) void: for entry from lwb spec to upb spec do print (name of spec [entry]); string report := "", separator := " failed for "; [] int inputs = inputs of spec [entry]; for value from lwb inputs to upb inputs do if bool expected = result of spec [entry]; function (inputs [value]) /= expected then report +:= separator + whole(inputs[value], 0); separator := " " fi od; print ((report = "" | (new line) | (new line, report, new line))) od;
  • 55. We instituted a rigorous regression test for all of the features of AWK. Any of the three of us who put in a new feature into the language [...], first had to write a test for the new feature. Alfred Aho http://www.computerworld.com.au/article/216844/a-z_programming_languages_awk/
  • 56. There is no such question as testing things after the fact with simulation models, but that in effect the testing and the replacement of simulations with modules that are deeper and more detailed goes on with the simulation model controlling, as it were, the place and order in which these things are done. Alan Perlis
  • 57. As design work progresses this simulation will gradually evolve into the real system. The simulation is the design. Tad B Pinkerton
  • 58.
  • 59. goto
  • 60.
  • 62. snowclone, noun ▪ clichéd wording used as a template, typically originating in a single quote ▪ e.g., "X considered harmful", "These aren't the Xs you're looking for", "X is the new Y", "It's X, but not as we know it", "No X left behind", "It's Xs all the way down", "All your X are belong to us"
  • 63.
  • 64. FUNCTION ISLEAP(YEAR) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) GOTO 20 IF (MOD(YEAR, 100) .EQ. 0) GOTO 10 IF (MOD(YEAR, 4) .EQ. 0) GOTO 20 10 ISLEAP = .FALSE. RETURN 20 ISLEAP = .TRUE. END
  • 65. FUNCTION ISLEAP(YEAR) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) GOTO 20 IF (MOD(YEAR, 100) .EQ. 0) GOTO 10 IF (MOD(YEAR, 4) .EQ. 0) GOTO 20 10 ISLEAP = .FALSE. RETURN 20 ISLEAP = .TRUE. RETURN END
  • 66. FUNCTION ISLEAP(YEAR) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) GOTO 20 IF (MOD(YEAR, 100) .EQ. 0) GOTO 10 IF (MOD(YEAR, 4) .EQ. 0) GOTO 20 10 ISLEAP = .FALSE. GOTO 30 20 ISLEAP = .TRUE. 30 RETURN END
  • 67. FUNCTION ISLEAP(YEAR) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) GOTO 20 IF (MOD(YEAR, 100) .EQ. 0) GOTO 10 IF (MOD(YEAR, 4) .EQ. 0) GOTO 20 10 ISLEAP = .FALSE. GOTO 30 20 ISLEAP = .TRUE. GOTO 30 30 RETURN END
  • 68. FUNCTION ISLEAP(YEAR) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) GOTO 20 IF (MOD(YEAR, 100) .EQ. 0) GOTO 10 IF (MOD(YEAR, 4) .EQ. 0) GOTO 20 10 ISLEAP = .FALSE. GOTO 30 20 ISLEAP = .TRUE. GOTO 30 30 CONTINUE RETURN END
  • 69. FUNCTION ISLEAP(Year) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) THEN ISLEAP = .TRUE. ELSE IF (MOD(YEAR, 100) .EQ. 0) THEN ISLEAP = .FALSE. ELSE IF (MOD(YEAR, 4) .EQ. 0) THEN ISLEAP = .TRUE. ELSE ISLEAP = .FALSE. END IF END
  • 70. FUNCTION ISLEAP(Year) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) THEN ISLEAP = .TRUE. ELSE IF (MOD(YEAR, 100) .EQ. 0) THEN ISLEAP = .FALSE. ELSE IF (MOD(YEAR, 4) .EQ. 0) THEN ISLEAP = .TRUE. ELSE ISLEAP = .FALSE. END IF END
  • 71. A goto completely invalidates the high-level structure of the code. Taligent's Guide to Designing Programs
  • 72. FUNCTION ISLEAP(YEAR) LOGICAL ISLEAP INTEGER YEAR IF (MOD(YEAR, 400) .EQ. 0) GOTO 20 IF (MOD(YEAR, 100) .EQ. 0) GOTO 10 IF (MOD(YEAR, 4) .EQ. 0) GOTO 20 10 ISLEAP = .FALSE. RETURN 20 ISLEAP = .TRUE. END
  • 73. send(to, from, count) register short *to, *from; register count; { register n=(count+7)/8; switch(count%8){ case 0: do{ *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; }while(--n>0); } }
  • 74. send(to, from, count) register short *to, *from; register count; { register n=(count+7)/8; switch(count%8){ case 0: do{ *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; }while(--n>0); } } I feel a combination of pride and revulsion at this discovery. Tom Duff
  • 75. send(to, from, count) register short *to, *from; register count; { register n=(count+7)/8; switch(count%8){ case 0: do{ *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; }while(--n>0); } } Many people have said that the worst feature of C is that switches don't break automatically before each case label. This code forms some sort of argument in that debate, but I'm not sure whether it's for or against. Tom Duff
  • 76. break
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92. One of the most powerful mechanisms for program structuring [...] is the block and procedure concept. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 94. Main Program and Subroutine The goal is to decompose a program into smaller pieces to help achieve modifiability. A program is decomposed hierarchically. Len Bass, Paul Clements & Rick Kazman Software Architecture in Practice
  • 95. afferent branch transform branch efferent branch main subroutine subroutine subroutine subroutine subroutine subroutine subroutine subroutine
  • 96. There is typically a single thread of control and each component in the hierarchy gets this control (optionally along with some data) from its parent and passes it along to its children. Len Bass, Paul Clements & Rick Kazman Software Architecture in Practice
  • 97. afferent branch transform branch efferent branch main subroutine subroutine subroutine subroutine subroutine subroutine subroutine subroutine
  • 98. afferent branch transform branch efferent branch main procedure procedure procedure procedure procedure procedure procedure procedure
  • 99. afferent branch transform branch efferent branch main function function function function function function function function
  • 101. You cannot teach beginners top-down programming, because they don't know which end is up. C A R Hoare
  • 102. Everything should be built top-down, except the first time. Alan Perlis
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112. Hamlet: To be, or not to be, that is the question.
  • 113. Ophelia: 'Tis in my memory locked, and you yourself shall keep the key of it.
  • 114. Hamlet: Yea, from the table of my memory I'll wipe away all trivial fond records.
  • 115.
  • 116. One of the most powerful mechanisms for program structuring [...] is the block and procedure concept. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 117. begin ref(Book) array books(1:capacity); integer count; procedure Push(top); ... procedure Pop; ... boolean procedure IsEmpty; ... boolean procedure IsFull; ... integer procedure Depth; ... ref(Book) procedure Top; ... count := 0 end;
  • 118. A procedure which is capable of giving rise to block instances which survive its call will be known as a class; and the instances will be known as objects of that class. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 119. class Stack(capacity); integer capacity; begin ref(Book) array books(1:capacity); integer count; procedure Push(top); ... procedure Pop; ... boolean procedure IsEmpty; ... boolean procedure IsFull; ... integer procedure Depth; ... ref(Book) procedure Top; ... count := 0 end;
  • 120. const newStack = () => { const items = [] return { depth: () => items.length, top: () => items[0], pop: () => { items.shift() }, push: newTop => { items.unshift(newTop) }, } }
  • 121. const newStack = () => { const items = [] return { depth: () => items.length, top: () => items[items.length - 1], pop: () => { items.pop() }, push: newTop => { items.push(newTop) }, } }
  • 122. Concatenation is an operation defined between two classes A and B, or a class A and a block C, and results in the formation of a new class or block. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 123. Concatenation consists in a merging of the attributes of both components, and the composition of their actions. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 124. const stackable = base => { const items = [] return Object.assign(base, { depth: () => items.length, top: () => items[items.length - 1], pop: () => { items.pop() }, push: newTop => { items.push(newTop) }, }) }
  • 125. const newStack = () => stackable({})
  • 126. const clearable = base => { return Object.assign(base, { clear: () => { while (base.depth()) base.pop() }, }) }
  • 127. const newStack = () => clearable(stackable({}))
  • 128. const newStack = () => compose(clearable, stackable)({}) const compose = (...funcs) => arg => funcs.reduceRight( (composed, func) => func(composed), arg)
  • 129. Concept Hierarchies The construction principle involved is best called abstraction; we concentrate on features common to many phenomena, and we abstract away features too far removed from the conceptual level at which we are working. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 130. A type hierarchy is composed of subtypes and supertypes. The intuitive idea of a subtype is one whose objects provide all the behavior of objects of another type (the supertype) plus something extra. Barbara Liskov "Data Abstraction and Hierarchy"
  • 131. What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T. Barbara Liskov "Data Abstraction and Hierarchy"
  • 132. const nonDuplicateTop = base => { const push = base.push return Object.assign(base, { push: newTop => { if (base.top() !== newTop) push(newTop) }, }) }
  • 133. tests = { ... 'A non-empty stack becomes deeper by retaining a pushed item as its top': () => { const stack = newStack() stack.push('ACCU') stack.push('2018') stack.push('2018') assert(stack.depth() === 3) assert(stack.top() === '2018') }, ... }
  • 134. const newStack = () => compose(clearable, stackable)({}) tests = { ... 'A non-empty stack becomes deeper by retaining a pushed item as its top': () => { const stack = newStack() stack.push('ACCU') stack.push('2018') stack.push('2018') assert(stack.depth() === 3) assert(stack.top() === '2018') }, ... }
  • 135. const newStack = () => compose(nonDuplicateTop, clearable, stackable)({}) tests = { ... 'A non-empty stack becomes deeper by retaining a pushed item as its top': () => { const stack = newStack() stack.push('ACCU') stack.push('2018') stack.push('2018') assert(stack.depth() === 3) assert(stack.top() === '2018') }, ... }
  • 136. What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T. Barbara Liskov "Data Abstraction and Hierarchy"
  • 137.
  • 138.
  • 139.
  • 140.
  • 141. Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation
  • 142. Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation The Synchronisation Quadrant
  • 143. Procedural Comfort Zone Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation
  • 144. Procedural Discomfort Zone Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation Procedural Comfort Zone
  • 145. Threads and locks — they’re kind of a dead end, right? BretVictor "The future of programming"
  • 146. So, I think if [...] we’re still using threads and locks, we should just, like, pack up and go home, ’cause we’ve clearly failed as an engineering field. BretVictor "The future of programming"
  • 147. Procedural Comfort Zone Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation
  • 148.
  • 149.
  • 150. single-threaded activity no shared mutable state coordination
  • 151.
  • 156.
  • 157. Toutes choses sont dites déjà; mais comme personne n'écoute, il faut toujours recommencer. André Gide
  • 158. Everything has been said before; but since nobody listens, we must always start again. André Gide