Compose Software Like Nature Would

Ca839bc293e4ca6f9fa327cf95a414a9?s=47 Ahmed Omran
September 15, 2017

Compose Software Like Nature Would

Inspired by biology background I combine some ideas from functional and OO programming into a talk about software design.

Ca839bc293e4ca6f9fa327cf95a414a9?s=128

Ahmed Omran

September 15, 2017
Tweet

Transcript

  1. Compose software like nature would @this_ahmed

  2. Feature Request

  3. Big Ball of Mud

  4. software

  5. change

  6. software as a living organism

  7. Earth: 4.5 billion YA

  8. Monads: 3.5 billion YA

  9. stromatolites

  10. The Machinery of Life David S. Goodsell

  11. small 1 μm

  12. cell membrane boundaries

  13. None
  14. None
  15. None
  16. easily replaced

  17. messages = colony

  18. Bacterial colony

  19. –Alan Kay “I thought of objects being like biological cells

    and/ or individual computers on a network, only able to communicate with messages…”
  20. Components: modules, objects, functions, etc. Messages: functions, properties, events, etc.

    Components with boundaries Compose with messages
  21. • easier to reason about (fits in your head) •

    easier to change (can be re-written) • easier to test (confidence when changing)
  22. None
  23. import myModule from ‘file.js'; // file.js export default function() {

    return something; } Boundaries
  24. Data Fetch Data Filter Line Graph data-fetch.js data-filter.js line-graph.js

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

  26. None
  27. Data Fetch Data Filter Line Graph /project |-- data-fetch.js |--

    data-filter.js |-- line-graph.js … 1000 other files What does system do?
  28. Multicellular: 1.5 billion YA

  29. stove-pipe sponge

  30. Mesh Data Fetch Data Filter Line Graph

  31. project └── dashboard └── sales-widget ├── data-fetch.js ├── data-filter.js ├──

    index.js └── line-graph.js
  32. sales-widget/index.js // import or inject components // compose our components

    const sales = dataFetch(“/sales"); const planSales = dataFilter(sales, plan); lineGraph(planSales);
  33. side-effects

  34. Nervous System: ~600 million YA

  35. Nerve Net

  36. push side-effects to the edges of our program

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

  38. Functional Core

  39. pure functions const increment = (n) => { n +

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

    // somewhere else array[0] // 1
  41. 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
  42. let newArr = [ ...prevArr ]; let newObj = {

    ...prevObj }; copy data
  43. Data Filter Data Shaper Line Graph Options Data (e.g. fetch

    api) Functional Core “Nerve Net” draw (e.g. chart.js)
  44. 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
  45. Cambrian Explosion: ~541 million YA

  46. None
  47. Run and Tumble mit.edu

  48. Run and Tumble to Better Design small components compose with

    messages push side-effects to boundaries functional core name things
  49. 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
  50. Compose software like nature would @this_ahmed