function rotateFuelRod(fuelRod, amount, inDegrees) {
...
}
function rotateControlRod(controlRod, amount, inRadians) {
...
}
Slide 47
Slide 47 text
function rotateFuelRod(fuelRod, amount, inDegrees) {
...
}
function rotateControlRod(controlRod, amount, inRadians) {
...
}
Slide 48
Slide 48 text
function rotateFuelRod(fuelRod, amount, inDegrees) {
...
}
function rotateControlRod(controlRod, amount, inRadians) {
...
}
Slide 49
Slide 49 text
bookFlight('ATL', true, false, true)
? ? ?
Slide 50
Slide 50 text
function bookFlight(airport, isPremium, hasCheckedLuggage, preferWindow) {
const luggageCost = hasCheckedLuggage
? ...
: ...
if (isPremium) {
if (hasCheckedLuggage) {
...
} else {
...
}
} else if (hasCheckedLuggage) {
...
} else {
...
}
}
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
– Martin Fowler
“…an API should be written to make it
easier for the caller, so if we know
where the caller is coming from we
should design the API with that
information in mind.”
Slide 53
Slide 53 text
Write code for humans
Not computers
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
bookFlight('ATL', 'Premium')
Slide 56
Slide 56 text
function bookFlight(airport, customerType) {
switch (customerType) {
case 'Premium':
...
case 'Regular':
...
default:
...
}
}
Slide 57
Slide 57 text
function bookFlight(airport, customerType) {
switch (customerType) {
case 'Premium':
...
case 'Regular':
...
default:
...
}
}
function getTime(person) {
if (doYouKnowTheTime(person)) {
return tellMeTheTime(person)
} else {
return `
Does anybody really know
what time it is?
`
}
}
Slide 97
Slide 97 text
function getTime(person) {
if (doYouKnowTheTime(person)) {
return tellMeTheTime(person)
} else {
return `
Does anybody really know
what time it is?
`
}
}
Slide 98
Slide 98 text
function getTime(person) {
if (doYouKnowTheTime(person)) {
return tellMeTheTime(person)
} else {
return `
Does anybody really know
what time it is?
`
}
}
Slide 99
Slide 99 text
function getTime(person) {
if (doYouKnowTheTime(person)) {
return tellMeTheTime(person)
} else {
return `
Does anybody really know
what time it is?
`
}
}
Slide 100
Slide 100 text
function getTime(person) {
if (doYouKnowTheTime(person)) {
return tellMeTheTime(person)
} else {
return tellMeTheTime(person)
}
}
Slide 101
Slide 101 text
Boolean Blindness
Slide 102
Slide 102 text
– Conor McBride
“To make use of a Boolean you
have to know its provenance so
that you can know what it
means.”
Slide 103
Slide 103 text
Get your organic,
homegrown
booleans from
Rhode Island!
Providence, RI
Slide 104
Slide 104 text
PROVENANCE
Slide 105
Slide 105 text
function findDogByName(name, dogs) {
if (name in dogs) {
return `${name} is a ${dogs[name].breed}`;
} else {
return 'Heck! No pupper found.';
}
}
Slide 106
Slide 106 text
function canDivide(denominator) {
return denominator != 0
}
function divisionResult(numerator, denominator) {
if (canDivide(denominator)) {
return `The result is ${numerator / denominator}`
} else {
return 'Could not divide'
}
}
Slide 107
Slide 107 text
function canDivide(denominator) {
return denominator != 0
}
function divisionResult(numerator, denominator) {
if (canDivide(denominator)) {
return `The result is ${numerator / denominator}`
} else {
return 'Could not divide'
}
}
Slide 108
Slide 108 text
function divisionResult(numerator, denominator) {
if (canDivide(denominator)) {
return `The result is ${numerator / denominator}`
} else {
return `The result is ${numerator / denominator}`
}
}
Slide 109
Slide 109 text
– Dan Licata
“Boolean tests let you look,
options let you see.”
Slide 110
Slide 110 text
Alternative
Return Values
Slide 111
Slide 111 text
type Maybe a
= Nothing
| Just a
Slide 112
Slide 112 text
type Maybe a
= Nothing
| Just a
Slide 113
Slide 113 text
type Maybe a
= Nothing
| Just a
Slide 114
Slide 114 text
type Maybe a
= Nothing
| Just a
Slide 115
Slide 115 text
42
Just 42
"Hi"
Just "Hi"
Slide 116
Slide 116 text
Just 42 [42]
Nothing [ ]
Slide 117
Slide 117 text
import { Maybe } from 'true-myth'
Maybe.just(42) // Just 42
Maybe.nothing() // Nothing
Maybe.of(42) // Just 42
Maybe.of(null) // Nothing
Maybe.of(undefined) // Nothing
Slide 118
Slide 118 text
function findDogByName(name, dogs) {
return Maybe.of(dogs[name])
.map(dog => `${name} is a ${dog.breed}.`)
.unwrapOr('Heck! No pupper found!')
}
Slide 119
Slide 119 text
function findDogByName(name, dogs) {
return Maybe.of(dogs[name])
.map(dog => `${name} is a ${dog.breed}.`)
.unwrapOr('Heck! No pupper found!')
}
Slide 120
Slide 120 text
function findDogByName(name, dogs) {
return Maybe.of(dogs[name])
.map(dog => `${name} is a ${dog.breed}.`)
.unwrapOr('Heck! No pupper found!')
}
Slide 121
Slide 121 text
function findDogByName(name, dogs) {
return Maybe.of(dogs[name])
.map(dog => `${name} is a ${dog.breed}.`)
.unwrapOr('Heck! No pupper found!')
}
function App({ dog }) {
switch (dog.status) {
case RemoteDoggo.Ready:
return
case RemoteDoggo.Fetching:
return
case RemoteDoggo.Success:
return
case RemoteDoggo.Fail:
return
}
}
Slide 138
Slide 138 text
function App({ dog }) {
switch (dog.status) {
case RemoteDoggo.Ready:
return
case RemoteDoggo.Fetching:
return
case RemoteDoggo.Success:
return
case RemoteDoggo.Fail:
return
}
}
function App({ dog }: AppProps): React.ReactElement {
switch (dog.kind) {
case Status.Ready:
return
case Status.Fetching:
return
case Status.Success:
return
// case Status.Fail:
// return
}
}
Slide 141
Slide 141 text
app.tsx:20:34 - error TS2366:
Function lacks ending return statement
and return type does not include 'undefined'.
20 function App({ dog }: AppProps): React.ReactElement {
~~~~~~~~~~~~~~~~~~
Found 1 error.
Slide 142
Slide 142 text
Impossible state becomes impossible*
Code becomes understandable
*trademark Richard Feldman
Slide 143
Slide 143 text
But wait,
There’s MORE!
AS SEEN ON
U I
Slide 144
Slide 144 text
Save to archive
Slide 145
Slide 145 text
Save to archive
A wild checkbox appears!
Slide 146
Slide 146 text
Save to archive
✓
Slide 147
Slide 147 text
Save to archive
?
Slide 148
Slide 148 text
No content
Slide 149
Slide 149 text
We design APIs for callers
So we should design UIs for users
Slide 150
Slide 150 text
No content
Slide 151
Slide 151 text
hu·mane
having or showing compassion or
benevolence
Slide 152
Slide 152 text
Save to archive
?
Slide 153
Slide 153 text
Save to archive
Save to inbox
Slide 154
Slide 154 text
Save to archive
Save to inbox
Slide 155
Slide 155 text
Save to archive
Save to inbox
Verb labels = when will it happen?
Slide 156
Slide 156 text
Saved to archive
Saved to inbox
Adjective labels = describe the final result.
Slide 157
Slide 157 text
Goodbye, boolean?
Slide 158
Slide 158 text
B A L A N C E
Slide 159
Slide 159 text
EMPATHY
Slide 160
Slide 160 text
Jeremy Fairbank
@elpapapollo
Slides: bit.ly/ct-bool