Slide 1

Slide 1 text

Compose software like nature would @this_ahmed

Slide 2

Slide 2 text

Feature Request

Slide 3

Slide 3 text

Big Ball of Mud

Slide 4

Slide 4 text

software

Slide 5

Slide 5 text

change

Slide 6

Slide 6 text

software as a living organism

Slide 7

Slide 7 text

Earth: 4.5 billion YA

Slide 8

Slide 8 text

Monads: 3.5 billion YA

Slide 9

Slide 9 text

stromatolites

Slide 10

Slide 10 text

The Machinery of Life David S. Goodsell

Slide 11

Slide 11 text

small 1 μm

Slide 12

Slide 12 text

cell membrane boundaries

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

easily replaced

Slide 17

Slide 17 text

messages = colony

Slide 18

Slide 18 text

Bacterial colony

Slide 19

Slide 19 text

–Alan Kay “I thought of objects being like biological cells and/ or individual computers on a network, only able to communicate with messages…”

Slide 20

Slide 20 text

Components: modules, objects, functions, etc. Messages: functions, properties, events, etc. Components with boundaries Compose with messages

Slide 21

Slide 21 text

• easier to reason about (fits in your head) • easier to change (can be re-written) • easier to test (confidence when changing)

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

import myModule from ‘file.js'; // file.js export default function() { return something; } Boundaries

Slide 24

Slide 24 text

Data Fetch Data Filter Line Graph data-fetch.js data-filter.js line-graph.js

Slide 25

Slide 25 text

Data Fetch Data Filter Bar Graph change data-fetch.js data-filter.js bar-graph.js

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Data Fetch Data Filter Line Graph /project |-- data-fetch.js |-- data-filter.js |-- line-graph.js … 1000 other files What does system do?

Slide 28

Slide 28 text

Multicellular: 1.5 billion YA

Slide 29

Slide 29 text

stove-pipe sponge

Slide 30

Slide 30 text

Mesh Data Fetch Data Filter Line Graph

Slide 31

Slide 31 text

project └── dashboard └── sales-widget ├── data-fetch.js ├── data-filter.js ├── index.js └── line-graph.js

Slide 32

Slide 32 text

sales-widget/index.js // import or inject components // compose our components const sales = dataFetch(“/sales"); const planSales = dataFilter(sales, plan); lineGraph(planSales);

Slide 33

Slide 33 text

side-effects

Slide 34

Slide 34 text

Nervous System: ~600 million YA

Slide 35

Slide 35 text

Nerve Net

Slide 36

Slide 36 text

push side-effects to the edges of our program

Slide 37

Slide 37 text

Data (e.g. fetch api) “Nerve Net” draw (e.g. chart.js)

Slide 38

Slide 38 text

Functional Core

Slide 39

Slide 39 text

pure functions const increment = (n) => { n + 1; };

Slide 40

Slide 40 text

mutable data const array = [3,1,2]; array[0] // 3 array.sort(); // somewhere else array[0] // 1

Slide 41

Slide 41 text

immutable data const array = Object.freeze([3,1,2]); array[0] // 3 array.sort(); // TypeError: Cannot assign to read only property '1' ... array[0] // 3

Slide 42

Slide 42 text

let newArr = [ ...prevArr ]; let newObj = { ...prevObj }; copy data

Slide 43

Slide 43 text

Data Filter Data Shaper Line Graph Options Data (e.g. fetch api) Functional Core “Nerve Net” draw (e.g. chart.js)

Slide 44

Slide 44 text

Data Filter Data Shaper Line Graph Options Data (e.g. fetch api) Functional Core “Nerve Net” draw (e.g. chart.js) Date Filter TrendLine Gary Bernhardt, Boundaries

Slide 45

Slide 45 text

Cambrian Explosion: ~541 million YA

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Run and Tumble mit.edu

Slide 48

Slide 48 text

Run and Tumble to Better Design small components compose with messages push side-effects to boundaries functional core name things

Slide 49

Slide 49 text

Resources • Gary Bernhardt - Boundaries: https:// www.destroyallsoftware.com/talks/boundaries • Dan North - Software that Fits in Your Head: https:// www.youtube.com/watch?v=4Y0tOi7QWqM • Rich Hickey - Simple Made Easy: https://www.infoq.com/ presentations/Simple-Made-Easy • Jessica Kerr - Functional Principles for OO Development: https://www.youtube.com/watch?v=tq5SQ4W3gRI

Slide 50

Slide 50 text

Compose software like nature would @this_ahmed