1 of 35

Functional Architecture

Brian Lonsdorf

@drboolean

https://bit.ly/2Xq8CU4

2 of 35

Goal?

  • Modular
  • Extendable
  • Performant
  • Maintainable
  • Readable
  • etc

3 of 35

4 of 35

5 of 35

populateContainer

makeItemActive

renderPattern

6 of 35

expandZipCode() {}

getLatLong() {}

getPolygon() {}

save() {}

find() {}

destroy(){}

fullName() {}

averageScore() {}

friends() {}

lastLogin() {}

toString() {}

getCountry() {}

getState() {}

getNumber() {}

getStreet() {}

dedupe() {}

findMinimum() {}

intersection() {}

validate() {}

isPresent(){}

isUnique()

inEnum() {}

7 of 35

expandZipCode() {}

getLatLong() {}

getPolygon() {}

save() {}

find() {}

destroy(){}

fullName() {}

averageScore() {}

friends() {}

lastLogin() {}

toString() {}

getCountry() {}

getState() {}

getNumber() {}

getStreet() {}

dedupe() {}

findMinimum() {}

intersection() {}

validate() {}

isPresent(){}

isUnique()

inEnum() {}

User

Address

Validations

Utils

Repo

Geolocate

8 of 35

9 of 35

Address

User

Preferences

10 of 35

11 of 35

12 of 35

Metaphors?

  • Know about context and domain
  • Mixed metaphors: Processor, Converter, etc
  • Evolves/Blurs over time
  • Hodge-podge of functionality in each object

13 of 35

Procedures

14 of 35

Procedures

  • Can i run this twice in a row?
  • Which order do I need to run these in?
  • Is it changing other parts of the program?
  • How does it interact with others?

15 of 35

// associativeadd(add(x, y), z) == add(x, add(y, z))��// commutativeadd(x, y) == add(y, x)��// identityadd(x, 0) == x��// distributiveadd(multiply(x, y), multiply(x, z)) == multiply(x, add(y,z))

16 of 35

Functions with defined contracts

17 of 35

18 of 35

19 of 35

20 of 35

21 of 35

22 of 35

Highly

generalized functions

23 of 35

Composition

24 of 35

Composition

  • Satisfy use cases
  • Simple, understandable pieces
  • Reuse

  • Harder to change implementation
  • Harder for user to compose

25 of 35

Composition

  • Flexibility in implementation changes
  • Less use cases to support

  • Flags, if/else
  • Won’t satisfy all cases
  • Less reuse

26 of 35

Composition

27 of 35

28 of 35

29 of 35

30 of 35

Favor

composable

functions, mostly

31 of 35

32 of 35

33 of 35

34 of 35

CLI blog

All

Menu

Latest

Write

Create Author

Start

35 of 35

Exercises

Code https://drive.google.com/file/d/1XQr5SZvTJ7dFYChr5kV42zO2FMhSATOa/view?usp=sharing