SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
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
ABOUT ME

                        TWITTER.COM/FAUST45
                          GITHUB.COM/FAUST45




Monday, October 8, 12
What is programing about?

                Goal of program convert input to reasonable output.

                We calculate something and storing temp results in
                vars, until we can produce complete result.




Monday, October 8, 12
What is programing about?

                               temp            temp         complete
                              results         results         result




                        Calculates      Calculates      Calculates




Monday, October 8, 12
What is programing about?
   Program
     State

                               temp            temp         complete
                              results         results         result




                        Calculates      Calculates      Calculates




Monday, October 8, 12
What is programing about?
   Program
     State

                               temp            temp         complete
                              results         results         result




                        Calculates      Calculates      Calculates



                               Layer control order of calculations

Monday, October 8, 12
What is programing about?
   Program
     State

                               temp            temp         complete
                              results         results         result




                         Layer manages access to program state


                        Calculates      Calculates      Calculates



                               Layer control order of calculations

Monday, October 8, 12
Looks simple?
   Program
     State

                               temp            temp         complete
                              results         results         result




                         Layer manages access to program state


                        Calculates      Calculates      Calculates



                               Layer control order of calculations

Monday, October 8, 12
Lets add some complexity




Monday, October 8, 12
Lets make
                        control order layer
                        hard to understand




Monday, October 8, 12
Let’s split
                           control order layer
                        and hide in Calculate units



Monday, October 8, 12
Who can help us?




Monday, October 8, 12
GOTO




Monday, October 8, 12
Lets do the same with
                         state manages layer




Monday, October 8, 12
Lets make
                        state manages layer
                        hard to understand




Monday, October 8, 12
Lets split
                           state manages layer
                        and hide in Calculate units




Monday, October 8, 12
Example




Monday, October 8, 12
Example


                                  Will never
                                  happens




Monday, October 8, 12
Happy debugging suckers




Monday, October 8, 12
Any part of the program can
                        rewrite state, and it's not easy to
                           tell where it's happening.




Monday, October 8, 12
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
Thats most popular
                        programing style, for
                              today.
                            Imperative

Monday, October 8, 12
Where the answer?




Monday, October 8, 12
Functional Programming




Monday, October 8, 12
Functional model
   Program
     State

                               temp            temp         complete
                              results         results         result




                         Layer manages access to program state


                        Calculates      Calculates      Calculates



                               Layer control order of calculations

Monday, October 8, 12
You construct program
                    from units of pure
                       calculations


Monday, October 8, 12
Units of pure calculations
            have no direct access to
                  program state


Monday, October 8, 12
You pass a pice of state in
                    params


           function send_money(sender_account,
                               receiver_account,
                               amount_to_send)

Monday, October 8, 12
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
Calculations depends only
                 from params you passed,
                      nothing hidden



Monday, October 8, 12
Functional
    Program
      state
                              Pice of program
                                    state




                             Calculate

                               return result

Monday, October 8, 12
Imperative
    Program
      state
                                               Pice of program
                        dir                          state
                           ect
                                 acc
                                     ess

                                              Calculate

                                                return result

Monday, October 8, 12
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
Model where you don’t
                    rewrite values but
                   produce new values


Monday, October 8, 12
Clojure introduce fast
                           immutable data
                              structures

Monday, October 8, 12
Implemented with
                            Binary trees
                                and
                         structure sharing

Monday, October 8, 12
Monday, October 8, 12
Mutable data




Monday, October 8, 12
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

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (6)

Tesi Lato C
Tesi Lato CTesi Lato C
Tesi Lato C
 
Implementasi basis data dalam xampp
Implementasi basis data dalam xamppImplementasi basis data dalam xampp
Implementasi basis data dalam xampp
 
Transition happens
Transition happensTransition happens
Transition happens
 
Perancangan tabel database dengan menggunakan entity relationship diagram
Perancangan tabel database dengan menggunakan entity relationship diagramPerancangan tabel database dengan menggunakan entity relationship diagram
Perancangan tabel database dengan menggunakan entity relationship diagram
 
maharashtra
maharashtramaharashtra
maharashtra
 
biometrics
biometricsbiometrics
biometrics
 

Ähnlich wie In search of good design...

A false digital alibi on Mac OS X
A false digital alibi on Mac OS XA false digital alibi on Mac OS X
A false digital alibi on Mac OS XFabio Palomba
 
R12 d49656 gc10-apps dba 22
R12 d49656 gc10-apps dba 22R12 d49656 gc10-apps dba 22
R12 d49656 gc10-apps dba 22zeesniper
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsqlafa reg
 
Optimizing for change: Taking risks safely & e-commerce
Optimizing for change: Taking risks safely & e-commerceOptimizing for change: Taking risks safely & e-commerce
Optimizing for change: Taking risks safely & e-commerceKellan
 
UEMB270: Software Distribution Under The Hood
UEMB270: Software Distribution Under The HoodUEMB270: Software Distribution Under The Hood
UEMB270: Software Distribution Under The HoodIvanti
 
Quality assurance in distributed continuous delivery
Quality assurance in distributed continuous deliveryQuality assurance in distributed continuous delivery
Quality assurance in distributed continuous deliverymingjin
 
Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and howPetr Zapletal
 
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Flink Forward
 
iOS Development. Some practices.
iOS Development. Some practices.iOS Development. Some practices.
iOS Development. Some practices.Alexander Lobunets
 
MWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To YouMWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To YouPeter Presnell
 
QConSF 2014 talk on Netflix Mantis, a stream processing system
QConSF 2014 talk on Netflix Mantis, a stream processing systemQConSF 2014 talk on Netflix Mantis, a stream processing system
QConSF 2014 talk on Netflix Mantis, a stream processing systemDanny Yuan
 
The Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms ProgrammingThe Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms ProgrammingJuan J. Merelo
 
The free lunch is over
The free lunch is overThe free lunch is over
The free lunch is overThadeu Russo
 
Reactive programming with RxJS - Taiwan
Reactive programming with RxJS - TaiwanReactive programming with RxJS - Taiwan
Reactive programming with RxJS - Taiwanmodernweb
 
Architecting large Node.js applications
Architecting large Node.js applicationsArchitecting large Node.js applications
Architecting large Node.js applicationsSergi Mansilla
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataDataWorks Summit/Hadoop Summit
 

Ähnlich wie In search of good design... (20)

A false digital alibi on Mac OS X
A false digital alibi on Mac OS XA false digital alibi on Mac OS X
A false digital alibi on Mac OS X
 
R12 d49656 gc10-apps dba 22
R12 d49656 gc10-apps dba 22R12 d49656 gc10-apps dba 22
R12 d49656 gc10-apps dba 22
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
 
A false digital alibi on mac os x
A false digital alibi on mac os xA false digital alibi on mac os x
A false digital alibi on mac os x
 
Optimizing for change: Taking risks safely & e-commerce
Optimizing for change: Taking risks safely & e-commerceOptimizing for change: Taking risks safely & e-commerce
Optimizing for change: Taking risks safely & e-commerce
 
UEMB270: Software Distribution Under The Hood
UEMB270: Software Distribution Under The HoodUEMB270: Software Distribution Under The Hood
UEMB270: Software Distribution Under The Hood
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Basics of R
Basics of RBasics of R
Basics of R
 
Quality assurance in distributed continuous delivery
Quality assurance in distributed continuous deliveryQuality assurance in distributed continuous delivery
Quality assurance in distributed continuous delivery
 
Cattles and Pets
Cattles and PetsCattles and Pets
Cattles and Pets
 
Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and how
 
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
Keynote: Building and Operating A Serverless Streaming Runtime for Apache Bea...
 
iOS Development. Some practices.
iOS Development. Some practices.iOS Development. Some practices.
iOS Development. Some practices.
 
MWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To YouMWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To You
 
QConSF 2014 talk on Netflix Mantis, a stream processing system
QConSF 2014 talk on Netflix Mantis, a stream processing systemQConSF 2014 talk on Netflix Mantis, a stream processing system
QConSF 2014 talk on Netflix Mantis, a stream processing system
 
The Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms ProgrammingThe Art of Evolutionary Algorithms Programming
The Art of Evolutionary Algorithms Programming
 
The free lunch is over
The free lunch is overThe free lunch is over
The free lunch is over
 
Reactive programming with RxJS - Taiwan
Reactive programming with RxJS - TaiwanReactive programming with RxJS - Taiwan
Reactive programming with RxJS - Taiwan
 
Architecting large Node.js applications
Architecting large Node.js applicationsArchitecting large Node.js applications
Architecting large Node.js applications
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing data
 

In search of good design...

  • 1. 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
  • 2. ABOUT ME TWITTER.COM/FAUST45 GITHUB.COM/FAUST45 Monday, October 8, 12
  • 3. What is programing about? Goal of program convert input to reasonable output. We calculate something and storing temp results in vars, until we can produce complete result. Monday, October 8, 12
  • 4. What is programing about? temp temp complete results results result Calculates Calculates Calculates Monday, October 8, 12
  • 5. What is programing about? Program State temp temp complete results results result Calculates Calculates Calculates Monday, October 8, 12
  • 6. What is programing about? Program State temp temp complete results results result Calculates Calculates Calculates Layer control order of calculations Monday, October 8, 12
  • 7. What is programing about? Program State temp temp complete results results result Layer manages access to program state Calculates Calculates Calculates Layer control order of calculations Monday, October 8, 12
  • 8. Looks simple? Program State temp temp complete results results result Layer manages access to program state Calculates Calculates Calculates Layer control order of calculations Monday, October 8, 12
  • 9. Lets add some complexity Monday, October 8, 12
  • 10. Lets make control order layer hard to understand Monday, October 8, 12
  • 11. Let’s split control order layer and hide in Calculate units Monday, October 8, 12
  • 12. Who can help us? Monday, October 8, 12
  • 14. Lets do the same with state manages layer Monday, October 8, 12
  • 15. Lets make state manages layer hard to understand Monday, October 8, 12
  • 16. Lets split state manages layer and hide in Calculate units Monday, October 8, 12
  • 18. Example Will never happens Monday, October 8, 12
  • 20. Any part of the program can rewrite state, and it's not easy to tell where it's happening. Monday, October 8, 12
  • 21. 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
  • 22. Thats most popular programing style, for today. Imperative Monday, October 8, 12
  • 23. Where the answer? Monday, October 8, 12
  • 25. Functional model Program State temp temp complete results results result Layer manages access to program state Calculates Calculates Calculates Layer control order of calculations Monday, October 8, 12
  • 26. You construct program from units of pure calculations Monday, October 8, 12
  • 27. Units of pure calculations have no direct access to program state Monday, October 8, 12
  • 28. You pass a pice of state in params function send_money(sender_account, receiver_account, amount_to_send) Monday, October 8, 12
  • 29. 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
  • 30. Calculations depends only from params you passed, nothing hidden Monday, October 8, 12
  • 31. Functional Program state Pice of program state Calculate return result Monday, October 8, 12
  • 32. Imperative Program state Pice of program dir state ect acc ess Calculate return result Monday, October 8, 12
  • 33. 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
  • 34. Model where you don’t rewrite values but produce new values Monday, October 8, 12
  • 35. Clojure introduce fast immutable data structures Monday, October 8, 12
  • 36. Implemented with Binary trees and structure sharing Monday, October 8, 12
  • 39. 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