The C Programming Language cover by Prentice Hall
Code Complete 2 cover by Pearson
function doSomething(anArg) {
let i, total = 0, max, min;
max = getMax(anArg);
min = max < 100 ? 0 : 100;
for (i = min; i < max; i++) {
total += i;
}
}
function doSomething(anArg) {
let max = getMax(anArg);
let min = max < 100 ? 0 : 100;
let total = 0;
for (let i = min; i < max; i++) {
total += i;
}
}
function doSomething(anArg) {
let max = getMax(anArg);
let min = max < 100 ? 0 : 100;
let total = getTotal(min, max);
}
function getTotal(min, max) {
let total = 0;
for (let i = min; i < max; i++) {
total += i;
}
return total;
}
Two fundamental rules:
Purity: when a function—
Benefits:
Purity: when a function—
“Computer Science” reasoning:
“Computer Science” reasoning:
“Code change” reasoning:
“Computer Science” reasoning:
“Code change” reasoning:
The most important reasoning:
variable scope
variable scope
variable scope
control over mutability
variable scope
control over mutability
variable scope
control over mutability
purity & immutability → referential transparency
…our intellectual powers are rather geared to master static relations and… our powers to visualize processes evolving in time are relatively poorly developed. For that reason we should do (as wise programmers aware of our limitations) our utmost to shorten the conceptual gap between the static program and the dynamic process, to make the correspondence between the program (spread out in text space) and the process (spread out in time) as trivial as possible.
“
—Edgar Djikstra, “Go To Considered Harmful”, 1968
…our intellectual powers are rather geared to master static relations and… our powers to visualize processes evolving in time are relatively poorly developed. For that reason we should do (as wise programmers aware of our limitations) our utmost to shorten the conceptual gap between the static program and the dynamic process, to make the correspondence between the program (spread out in text space) and the process (spread out in time) as trivial as possible.
“
—Edgar Djikstra, “Go To Considered Harmful”, 1968
shorten the conceptual gap between the
static program and the dynamic process,
“
between the program
in text space
and the process
in time
“
—Edgar Djikstra, “Go To Considered Harmful”, 1968
shorten the conceptual gap between the
static program and the dynamic process,
“
between the program
in text space
and the process
in time
…
…
…
…
global reasoning
GOTO:
local reasoning
structured programming:
local reasoning
structured programming:
global reasoning
GOTO:
reasoning about control flow
local reasoning
explicit argument passing:
global reasoning
global mutable variables:
reasoning about data change
reasoning about class methods
encapsulated data:
reasoning about any function
shared mutable data:
reasoning about data change
reasoning about interfaces
reasoning about fault tolerance
independent failure & recovery
actor-based systems:
system-wide failure & recovery
monolithic systems:
class User {
constructor(
name: string,
age: number,
email: string,
state: State,
) {}
}
class User {
constructor(
name: string,
age: number,
email: string,
state: State,
) {}
}
function describe(user: User): string {
return `${user.name} is ${user.age} years old`;
}
class User {
constructor(
name: string,
age: number,
email: string,
state: State,
) {}
}
function describe(person: { name: string; age: number }): string {
return `${person.name} is ${person.age} years old`;
}
reasoning about a
describe(user: User) {...}
whole class
describe(person: { name: string, age: number }) {...}
reasoning about
structured data
describe(user: User) {...}
describe(person: { name: string, age: number }) {...}
reasoning about data coupling
reasoning about
structured data
reasoning about a
whole class
consumer-driven
Observable-based systems:
owner-managed
Autotracking:
→ no arbitrary reactivity
→ no arbitrary “pushes”
reasoning about reactivity
consumer-driven
Observable-based systems:
owner-managed
Autotracking: