It's all about containing complexity.
Think of your modules as lego blocks.
You don't necessarily care about the
details of how each block is made.
All you need to know is how to use the
lego blocks to build your lego castle.
— @sindresorhus
Slide 26
Slide 26 text
Interfaces
Slide 27
Slide 27 text
Breaking
Down
Complexity
Slide 28
Slide 28 text
Aspect,
or Flow?
Slide 29
Slide 29 text
Portability
Slide 30
Slide 30 text
Composability
Slide 31
Slide 31 text
Composability
Slide 32
Slide 32 text
Modular
Design
Essentials
Slide 33
Slide 33 text
Single
Responsibility
Principle
Slide 34
Slide 34 text
API
First
Slide 35
Slide 35 text
Revealing
Pattern
Slide 36
Slide 36 text
Consistency
(across modules)
Slide 37
Slide 37 text
Ambiguity
Slide 38
Slide 38 text
Be conservative in
what you do, be
liberal in what you
accept from others.
— Postel's Law (from TCP)
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
Simplicity
Slide 41
Slide 41 text
Interface
Testing
Slide 42
Slide 42 text
Interface
Documentation
Slide 43
Slide 43 text
Abstraction
Slide 44
Slide 44 text
The
Holy
Grail!
Slide 45
Slide 45 text
Oh no.
Slide 46
Slide 46 text
Premature
Abstraction
Slide 47
Slide 47 text
The
Right
Abstraction
Slide 48
Slide 48 text
Refactoring
Complex
Code
Slide 49
Slide 49 text
Less
Clever*
Code.
(way less.)
*
Slide 50
Slide 50 text
Use
More*
Variables!
(way more.)
*
Slide 51
Slide 51 text
() => a && (b ? c : d) || e
if (a) {
return b ? c : d
}
return e
Slide 52
Slide 52 text
Guard
Clauses
Slide 53
Slide 53 text
if (apiKey) {
if (apiSecret) {
// happy path
} else {
throw new Error('missing secret')
}
} else {
throw new Error('missing key')
}
Slide 54
Slide 54 text
if (!apiKey) {
throw new Error('missing key')
}
if (!apiSecret) {
throw new Error('missing secret')
}
// happy path
Slide 55
Slide 55 text
Extract
Function
Slide 56
Slide 56 text
let optionalLabel = null
if (labelText) {
optionalLabel = (
{ labelText }
)
}