in search of good design
TRANSCRIPT
![Page 1: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/1.jpg)
In search of good design...
// When I wrote this code, only God and I understood what I was doing// Now, God only knows
Monday, October 8, 12
![Page 2: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/2.jpg)
ABOUT ME
TWITTER.COM/FAUST45GITHUB.COM/FAUST45
Monday, October 8, 12
![Page 3: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/3.jpg)
Goal of program convert input to reasonable output.
We calculate something and storing temp results in vars, until we can produce complete result.
What is programing about?
Monday, October 8, 12
![Page 4: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/4.jpg)
What is programing about?
Calculates Calculates Calculates
temp results
temp results
complete result
Monday, October 8, 12
![Page 5: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/5.jpg)
What is programing about?
Calculates Calculates Calculates
temp results
temp results
complete result
Program State
Monday, October 8, 12
![Page 6: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/6.jpg)
What is programing about?
Calculates Calculates Calculates
temp results
temp results
complete result
Program State
Layer control order of calculations
Monday, October 8, 12
![Page 7: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/7.jpg)
What is programing about?
Calculates Calculates Calculates
temp results
temp results
complete result
Program State
Layer manages access to program state
Layer control order of calculations
Monday, October 8, 12
![Page 8: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/8.jpg)
Looks simple?
Calculates Calculates Calculates
temp results
temp results
complete result
Program State
Layer manages access to program state
Layer control order of calculations
Monday, October 8, 12
![Page 9: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/9.jpg)
Lets add some complexity
Monday, October 8, 12
![Page 10: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/10.jpg)
Lets make control order layer hard to understand
Monday, October 8, 12
![Page 11: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/11.jpg)
Let’s split control order layer
and hide in Calculate units
Monday, October 8, 12
![Page 12: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/12.jpg)
Who can help us?
Monday, October 8, 12
![Page 13: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/13.jpg)
GOTO
Monday, October 8, 12
![Page 14: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/14.jpg)
Lets do the same with state manages layer
Monday, October 8, 12
![Page 15: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/15.jpg)
Lets makestate manages layer hard to understand
Monday, October 8, 12
![Page 16: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/16.jpg)
Lets split state manages layer
and hide in Calculate units
Monday, October 8, 12
![Page 17: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/17.jpg)
Example
Monday, October 8, 12
![Page 18: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/18.jpg)
Example
Will never happens
Monday, October 8, 12
![Page 19: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/19.jpg)
Happy debugging suckers
Monday, October 8, 12
![Page 20: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/20.jpg)
Any part of the program can rewrite state, and it's not easy to
tell where it's happening.
Monday, October 8, 12
![Page 21: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/21.jpg)
Unit tests don’t save us
Unit test passed success.
Only when you run all program you can touch the bug
Monday, October 8, 12
![Page 22: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/22.jpg)
Thats most popular programing style, for
today.Imperative
Monday, October 8, 12
![Page 23: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/23.jpg)
Where the answer?
Monday, October 8, 12
![Page 24: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/24.jpg)
Functional Programming
Monday, October 8, 12
![Page 25: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/25.jpg)
Functional model
Calculates Calculates Calculates
temp results
temp results
complete result
Program State
Layer manages access to program state
Layer control order of calculations
Monday, October 8, 12
![Page 26: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/26.jpg)
You construct program from units of pure
calculations
Monday, October 8, 12
![Page 27: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/27.jpg)
Units of pure calculations have no direct access to
program state
Monday, October 8, 12
![Page 28: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/28.jpg)
You pass a pice of state in params
function send_money(sender_account, receiver_account, amount_to_send)
Monday, October 8, 12
![Page 29: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/29.jpg)
and return result of calculations, some new pice of state
function send_money(sender_account, ...) return how_sender_account_looks_after_money_was_send
Monday, October 8, 12
![Page 30: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/30.jpg)
Calculations depends only from params you passed,
nothing hidden
Monday, October 8, 12
![Page 31: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/31.jpg)
Calculate
Pice of program state
return result
Program state
Functional
Monday, October 8, 12
![Page 32: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/32.jpg)
Calculate
Pice of program state
return result
Program state
Imperative
direct access
Monday, October 8, 12
![Page 33: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/33.jpg)
Rich Hickey
Creator of clojure, language with immutable data by default.
Dialect of Lisp on top of Java Virtual Machine
He was inspired by paper “Out of the Tar Pit”
Monday, October 8, 12
![Page 34: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/34.jpg)
Model where you don’t rewrite values but
produce new values
Monday, October 8, 12
![Page 35: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/35.jpg)
Clojure introduce fast immutable data
structures
Monday, October 8, 12
![Page 36: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/36.jpg)
Implemented with Binary trees
and structure sharing
Monday, October 8, 12
![Page 37: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/37.jpg)
Monday, October 8, 12
![Page 38: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/38.jpg)
Mutable data
Monday, October 8, 12
![Page 39: In search of good design](https://reader034.vdocuments.us/reader034/viewer/2022042814/555193c3b4c90580128b55e7/html5/thumbnails/39.jpg)
Resources
★ “Out of the Tar Pit”★ “The Art of Unix Programming”★ “Functional programming is a ghetto” (blog bost by Michael O.Church)★ Rich Hickey videos★ Stuart Holloway videos - “Simplicity Ain't Easy”
Monday, October 8, 12