SlideShare uma empresa Scribd logo
1 de 53
Threading is not a model Joe Gregorio Developer Relations, Google Wave
Scope My Opinion
Goal I want to annoy you.
The path A short story, a book, design patterns, and Djikstra
The Principle of Sufficient Irritation "The Short Happy Life  of the Brown Oxford" Philip K. Dick The short story
The Principle of Sufficient Irritation in action Determining the radioactive irritant is left as an exercise for the reader.
The path A  short story ,  a book, design patterns, and Djikstra
The Design of Everyday Things The book
The path A short story, a book ,  design patterns, and Djikstra
Setting the record straight Let's talk about Design Patterns I  did not  say that patterns are bad. I  did  say that using them may be a sign of weakness in a language.
A Blog Post Python isn't Java without the compile Design Patterns in Dynamic Programming – Peter Norvig Beyond Java – Bruce Tate
Language Not talking just about Python
Language Aren't patterns good? Yes, but also a sign of weakness
There is a lack of patterns in Python 1. Define 'lack of patterns' 2. Demonstrate that lack 3. Explain why
Hard numbers comp.lang.python 100,000+ messages
Hard numbers “ factory method pattern” - 0 “ abstract-factory pattern” - 0 “ flyweight pattern” - 3 “ state pattern” - 10 “ strategy pattern” - 25 “ flyweight” - 36 “ visitor pattern” - 60
For your comparison “ dark matter” - 2
For your comparison “ dark matter” - 2 “ the pope” - 16
For your comparison “ dark matter” - 2 “ the pope” - 16 “ sausage” - 66 Presuming there is no overlap among these messages
There is a lack of patterns in Python 1.  Define 'lack of patterns' 2.  Demonstrate that lack 3. Explain why
Explain Why The patterns are built in. No one talks about the 'structured programming' pattern or the 'object-oriented' pattern any more.
Strategy Pattern on comp.lang.python class  Bisection (FindMinima): def  algorithm(self,line): return  (5.5,6.6) class  ConjugateGradient (FindMinima): def  algorithm(self,line): return  (3.3,4.4) class  MinimaSolver:  # context class strategy='' def  __init__ ( self ,strategy): self .strategy=strategy def  minima(self,line): return  self.strategy.algorithm(line) def  changeAlgorithm(self,newAlgorithm): self .strategy = newAlgorithm solver=MinimaSolver(ConjugateGradient()) print solver.minima(( 5.5 , 5.5 )) solver.changeAlgorithm(Bisection()) print solver.minima(( 5.5 , 5.5 ))
Strategy Pattern “ When most of your code does nothing in a pompous way that is a sure sign that you are heading in the wrong direction. Here's a translation into python” - Peter Otten
Strategy Pattern on comp.lang.python def   bisection(line): return   5.5 ,  6.6 def   conjugate_gradient(line): return   3.3 ,   4.4 solver = conjugate_gradient print solver(( 5.5 , 5.5 )) solver = bisection print solver(( 5.5 , 5.5 ))
Proof by Wikipedia “ This pattern is invisible in languages with first-class functions.” http://en.wikipedia.org/wiki/Strategy_pattern What other language features are there, and what patterns do they make invisible?
Catalog of Language Features First-class functions Meta-programming Iterators Closures
Proof by Wikipedia In object-oriented programming, the Iterator pattern is a design pattern in which iterators are used to access the elements of an aggregate object sequentially without exposing its underlying representation. http://en.wikipedia.org/wiki/Iterator_pattern The definition of low-hanging fruit.
Iterators for  element  in  [ 1 ,  2 ,  3 ]: print element for  element  in  ( 1 ,  2 ,  3 ): print element for  key  in  { 'one' : 1, 'two' : 2 }: print key for  char  in   "123" : print char for  line  in  open( "myfile.txt" ): print line
There is a lack of patterns in Python 1.  Define 'lack of patterns' 2.  Demonstrate that lack 3.  Explain why
The path A short story, a book , design patterns,  and Djikstra
Structured Programming "Go to statement considered harmful” Edsger W. Dijkstra,1968 Letter to the editor, Communications of the ACM , Volume 11, Issue 3  (March 1968)
Structured Programming We are talking about Routines! (or procedures, or functions, or methods) being controversial. Along with 'if', 'while', and 'switch' statements
The controversy went on for a while "GOTO Considered Harmful" Considered Harmful  Frank Rubin, 1987 Communications of the ACM, Vol. 30, No. 3. (March 1987), pp. 195-196.
With Structured Programming def  hyp(x, y) : return math.sqrt(x**2 + y**2) >> hyp(3, 4) 5
What if Structured Programming wasn't built in? You can do Structure Programming with our built in stack and 'call' primitives! def  hyp : push(pop()**2 + pop()**2) call math.sqrt return >> push(3) >> push(4) >> call hyp >> pop() 5
Patterns and Primitives Pattern Language Feature Primitives Model
Some Concurrency Patterns listed on Wikipedia Lock Monitor Object Reactor Thread pool Thread-specific storage These you will see on comp.lang.python
Some Concurrency Patterns listed on Wikipedia Lock Monitor Object Reactor Thread pool Thread-specific storage These you will see on comp.lang.python
Patterns and Primitives Threadpool (Pattern) Language Feature Threads + queue + lock (Primitives) Concurrency (Model)
“ Just” use threads Threading is not a model Threading is a primitive, along with locks, transactional memory, etc.
What are the concurrency models? ,[object Object]
Actors The difference is only in 'what' is concurrent
CSP Model ,[object Object]
An actual model for processes
All code is written single threaded
Communication via channels.
Sieve of Eratosthenes
Sieve of Eratosthenes N 2 3 5 7 11 13
CSP – Stackless – Primes import stackless def generate(ch): for i in range(2, 1000): ch.send(i) def pfilter(chin, chout, p): for i in chin: if i % p != 0: chout.send(i) def primes(chin): while 1: prime = chin.receive() print prime chout = stackless.channel() stackless.tasklet(pfilter)(chin, chout, prime) chin = chout c = stackless.channel() stackless.tasklet(generate)(c) stackless.tasklet(primes)(c) stackless.run()
CSP – Stackless – Primes import stackless def generate(ch): for i in range(2, 1000): ch.send(i) def pfilter(chin, chout, p): for i in chin: if i % p != 0: chout.send(i) def primes(chin): while 1: prime = chin.receive() print prime chout = stackless.channel() stackless.tasklet(pfilter)(chin, chout, prime) chin = chout c = stackless.channel() stackless.tasklet(generate)(c) stackless.tasklet(primes)(c) stackless.run() N 2 P n P n+1
CSP – Go – Primes func generate(ch chan int) { for i := 2; ; i++ { ch <- i } // Send 'i' to channel 'ch'. } func filter(in, out chan int, prime int) { for { i := <-in  // Receive 'i' from 'in'. if i % prime != 0 { out <- i } // Send 'i' to 'out'. } } func main() { ch := make(chan int)  // Create a new channel. go generate(ch)  // Start generate() as a goroutine. for { prime := <-ch fmt.Println(prime) ch1 := make(chan int) go   filter(ch, ch1, prime) ch = ch1 } } N 2 P n P n+1
CSP ,[object Object]
Locks

Mais conteúdo relacionado

Mais procurados

Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Threeamiable_indian
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundationKevlin Henney
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.Mosky Liu
 
Python2 unicode-pt1
Python2 unicode-pt1Python2 unicode-pt1
Python2 unicode-pt1abadger1999
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric SystemErin Dees
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - BasicMosky Liu
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 
JRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreJRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreErin Dees
 
Python interview questions for experience
Python interview questions for experiencePython interview questions for experience
Python interview questions for experienceMYTHILIKRISHNAN4
 
Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5Oregon Law Practice Management
 
Agapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.comAgapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.comAntonio Silva
 
Jerry Shea Resume And Addendum 5 2 09
Jerry  Shea Resume And Addendum 5 2 09Jerry  Shea Resume And Addendum 5 2 09
Jerry Shea Resume And Addendum 5 2 09gshea11
 
Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1Alejandra Perez
 
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi PetangMajlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi PetangImsamad
 

Mais procurados (20)

Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
C# p5
C# p5C# p5
C# p5
 
Python2 unicode-pt1
Python2 unicode-pt1Python2 unicode-pt1
Python2 unicode-pt1
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
JRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreJRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists Anymore
 
Python interview questions for experience
Python interview questions for experiencePython interview questions for experience
Python interview questions for experience
 
MMBJ Shanzhai Culture
MMBJ Shanzhai CultureMMBJ Shanzhai Culture
MMBJ Shanzhai Culture
 
Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5Washington Practitioners Significant Changes To Rpc 1.5
Washington Practitioners Significant Changes To Rpc 1.5
 
LoteríA Correcta
LoteríA CorrectaLoteríA Correcta
LoteríA Correcta
 
Agapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.comAgapornis Mansos - www.criadourosudica.blogspot.com
Agapornis Mansos - www.criadourosudica.blogspot.com
 
Jerry Shea Resume And Addendum 5 2 09
Jerry  Shea Resume And Addendum 5 2 09Jerry  Shea Resume And Addendum 5 2 09
Jerry Shea Resume And Addendum 5 2 09
 
Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1
 
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi PetangMajlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
 

Destaque

Ήπειρος Αρχέγονος Ελλάς. Μέρος 1ο : Απέραντη Ελληνική Χώρα.
Ήπειρος Αρχέγονος Ελλάς.  Μέρος 1ο : Απέραντη Ελληνική Χώρα. Ήπειρος Αρχέγονος Ελλάς.  Μέρος 1ο : Απέραντη Ελληνική Χώρα.
Ήπειρος Αρχέγονος Ελλάς. Μέρος 1ο : Απέραντη Ελληνική Χώρα. ΠΑΖΛ ΕΠΙΛΟΓΕΣ
 
MMMM Alejandro Quesada
MMMM Alejandro QuesadaMMMM Alejandro Quesada
MMMM Alejandro Quesadaguest744ab6
 
BAHILLERES Alejandro Quesada
BAHILLERES Alejandro QuesadaBAHILLERES Alejandro Quesada
BAHILLERES Alejandro Quesadaguest744ab6
 
Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ - ΜΕΡΟΣ 2ο: «ΜΗΓΑΡΙΣ ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...
Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ -  ΜΕΡΟΣ  2ο: «ΜΗΓΑΡΙΣ  ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ -  ΜΕΡΟΣ  2ο: «ΜΗΓΑΡΙΣ  ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...
Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ - ΜΕΡΟΣ 2ο: «ΜΗΓΑΡΙΣ ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...ΠΑΖΛ ΕΠΙΛΟΓΕΣ
 
Ήπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη Πατρίδα
Ήπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη ΠατρίδαΉπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη Πατρίδα
Ήπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη ΠατρίδαΠΑΖΛ ΕΠΙΛΟΓΕΣ
 
Αφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑ
Αφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑΑφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑ
Αφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑΠΑΖΛ ΕΠΙΛΟΓΕΣ
 
(Προτιμήστε την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...
(Προτιμήστε  την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...(Προτιμήστε  την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...
(Προτιμήστε την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...ΠΑΖΛ ΕΠΙΛΟΓΕΣ
 
Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων και η...
Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων  και η...Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων  και η...
Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων και η...ΠΑΖΛ ΕΠΙΛΟΓΕΣ
 

Destaque (9)

Ήπειρος Αρχέγονος Ελλάς. Μέρος 1ο : Απέραντη Ελληνική Χώρα.
Ήπειρος Αρχέγονος Ελλάς.  Μέρος 1ο : Απέραντη Ελληνική Χώρα. Ήπειρος Αρχέγονος Ελλάς.  Μέρος 1ο : Απέραντη Ελληνική Χώρα.
Ήπειρος Αρχέγονος Ελλάς. Μέρος 1ο : Απέραντη Ελληνική Χώρα.
 
MMMM Alejandro Quesada
MMMM Alejandro QuesadaMMMM Alejandro Quesada
MMMM Alejandro Quesada
 
Digital Wish
Digital WishDigital Wish
Digital Wish
 
BAHILLERES Alejandro Quesada
BAHILLERES Alejandro QuesadaBAHILLERES Alejandro Quesada
BAHILLERES Alejandro Quesada
 
Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ - ΜΕΡΟΣ 2ο: «ΜΗΓΑΡΙΣ ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...
Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ -  ΜΕΡΟΣ  2ο: «ΜΗΓΑΡΙΣ  ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ -  ΜΕΡΟΣ  2ο: «ΜΗΓΑΡΙΣ  ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...
Η ΕΛΛΗΝΙΚΗ ΓΛΩΣΣΑ - ΜΕΡΟΣ 2ο: «ΜΗΓΑΡΙΣ ΕΧΩ AΛΛΟ ΣΤΟ ΝΟY ΜΟΥ, ΠΑΡΕΞ ΕΛΕΥΘΕΡ...
 
Ήπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη Πατρίδα
Ήπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη ΠατρίδαΉπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη Πατρίδα
Ήπειρος Αρχέγονος Ελλάς. Μέρος 2ο : Βόρειος Ήπειρος, Αλησμόνητη Πατρίδα
 
Αφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑ
Αφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑΑφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑ
Αφυπνιστική Φωνή Πατέρων για ΜΕΤΑΝΟΙΑ
 
(Προτιμήστε την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...
(Προτιμήστε  την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...(Προτιμήστε  την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...
(Προτιμήστε την 2η Έκδοση) Η Αυτοκρατορία της Νέας Ρώμης και οι πολίτες της ...
 
Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων και η...
Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων  και η...Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων  και η...
Κυριακή της Ορθοδοξίας ( Α΄ Νηστειών) - H Αναστήλωση των Αγίων Εικόνων και η...
 

Semelhante a Threading Is Not A Model

Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonPython Ireland
 
Python 3000
Python 3000Python 3000
Python 3000Bob Chao
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientistsaeberspaecher
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийSigma Software
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experimentAmos Wenger
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experimentAmos Wenger
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsRuth Marvin
 
Tips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software EngineeringTips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software Engineeringjtdudley
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia岳華 杜
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 

Semelhante a Threading Is Not A Model (20)

Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
 
Python 3000
Python 3000Python 3000
Python 3000
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Design problem
Design problemDesign problem
Design problem
 
Python basic
Python basicPython basic
Python basic
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Tips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software EngineeringTips And Tricks For Bioinformatics Software Engineering
Tips And Tricks For Bioinformatics Software Engineering
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
 
Turbo prolog 2.0 basics
Turbo prolog 2.0 basicsTurbo prolog 2.0 basics
Turbo prolog 2.0 basics
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 

Último

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Último (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Threading Is Not A Model

  • 1. Threading is not a model Joe Gregorio Developer Relations, Google Wave
  • 3. Goal I want to annoy you.
  • 4. The path A short story, a book, design patterns, and Djikstra
  • 5. The Principle of Sufficient Irritation &quot;The Short Happy Life of the Brown Oxford&quot; Philip K. Dick The short story
  • 6. The Principle of Sufficient Irritation in action Determining the radioactive irritant is left as an exercise for the reader.
  • 7. The path A short story , a book, design patterns, and Djikstra
  • 8. The Design of Everyday Things The book
  • 9. The path A short story, a book , design patterns, and Djikstra
  • 10. Setting the record straight Let's talk about Design Patterns I did not say that patterns are bad. I did say that using them may be a sign of weakness in a language.
  • 11. A Blog Post Python isn't Java without the compile Design Patterns in Dynamic Programming – Peter Norvig Beyond Java – Bruce Tate
  • 12. Language Not talking just about Python
  • 13. Language Aren't patterns good? Yes, but also a sign of weakness
  • 14. There is a lack of patterns in Python 1. Define 'lack of patterns' 2. Demonstrate that lack 3. Explain why
  • 15. Hard numbers comp.lang.python 100,000+ messages
  • 16. Hard numbers “ factory method pattern” - 0 “ abstract-factory pattern” - 0 “ flyweight pattern” - 3 “ state pattern” - 10 “ strategy pattern” - 25 “ flyweight” - 36 “ visitor pattern” - 60
  • 17. For your comparison “ dark matter” - 2
  • 18. For your comparison “ dark matter” - 2 “ the pope” - 16
  • 19. For your comparison “ dark matter” - 2 “ the pope” - 16 “ sausage” - 66 Presuming there is no overlap among these messages
  • 20. There is a lack of patterns in Python 1. Define 'lack of patterns' 2. Demonstrate that lack 3. Explain why
  • 21. Explain Why The patterns are built in. No one talks about the 'structured programming' pattern or the 'object-oriented' pattern any more.
  • 22. Strategy Pattern on comp.lang.python class Bisection (FindMinima): def algorithm(self,line): return (5.5,6.6) class ConjugateGradient (FindMinima): def algorithm(self,line): return (3.3,4.4) class MinimaSolver: # context class strategy='' def __init__ ( self ,strategy): self .strategy=strategy def minima(self,line): return self.strategy.algorithm(line) def changeAlgorithm(self,newAlgorithm): self .strategy = newAlgorithm solver=MinimaSolver(ConjugateGradient()) print solver.minima(( 5.5 , 5.5 )) solver.changeAlgorithm(Bisection()) print solver.minima(( 5.5 , 5.5 ))
  • 23. Strategy Pattern “ When most of your code does nothing in a pompous way that is a sure sign that you are heading in the wrong direction. Here's a translation into python” - Peter Otten
  • 24. Strategy Pattern on comp.lang.python def bisection(line): return 5.5 , 6.6 def conjugate_gradient(line): return 3.3 , 4.4 solver = conjugate_gradient print solver(( 5.5 , 5.5 )) solver = bisection print solver(( 5.5 , 5.5 ))
  • 25. Proof by Wikipedia “ This pattern is invisible in languages with first-class functions.” http://en.wikipedia.org/wiki/Strategy_pattern What other language features are there, and what patterns do they make invisible?
  • 26. Catalog of Language Features First-class functions Meta-programming Iterators Closures
  • 27. Proof by Wikipedia In object-oriented programming, the Iterator pattern is a design pattern in which iterators are used to access the elements of an aggregate object sequentially without exposing its underlying representation. http://en.wikipedia.org/wiki/Iterator_pattern The definition of low-hanging fruit.
  • 28. Iterators for element in [ 1 , 2 , 3 ]: print element for element in ( 1 , 2 , 3 ): print element for key in { 'one' : 1, 'two' : 2 }: print key for char in &quot;123&quot; : print char for line in open( &quot;myfile.txt&quot; ): print line
  • 29. There is a lack of patterns in Python 1. Define 'lack of patterns' 2. Demonstrate that lack 3. Explain why
  • 30. The path A short story, a book , design patterns, and Djikstra
  • 31. Structured Programming &quot;Go to statement considered harmful” Edsger W. Dijkstra,1968 Letter to the editor, Communications of the ACM , Volume 11, Issue 3 (March 1968)
  • 32. Structured Programming We are talking about Routines! (or procedures, or functions, or methods) being controversial. Along with 'if', 'while', and 'switch' statements
  • 33. The controversy went on for a while &quot;GOTO Considered Harmful&quot; Considered Harmful Frank Rubin, 1987 Communications of the ACM, Vol. 30, No. 3. (March 1987), pp. 195-196.
  • 34. With Structured Programming def hyp(x, y) : return math.sqrt(x**2 + y**2) >> hyp(3, 4) 5
  • 35. What if Structured Programming wasn't built in? You can do Structure Programming with our built in stack and 'call' primitives! def hyp : push(pop()**2 + pop()**2) call math.sqrt return >> push(3) >> push(4) >> call hyp >> pop() 5
  • 36. Patterns and Primitives Pattern Language Feature Primitives Model
  • 37. Some Concurrency Patterns listed on Wikipedia Lock Monitor Object Reactor Thread pool Thread-specific storage These you will see on comp.lang.python
  • 38. Some Concurrency Patterns listed on Wikipedia Lock Monitor Object Reactor Thread pool Thread-specific storage These you will see on comp.lang.python
  • 39. Patterns and Primitives Threadpool (Pattern) Language Feature Threads + queue + lock (Primitives) Concurrency (Model)
  • 40. “ Just” use threads Threading is not a model Threading is a primitive, along with locks, transactional memory, etc.
  • 41.
  • 42. Actors The difference is only in 'what' is concurrent
  • 43.
  • 44. An actual model for processes
  • 45. All code is written single threaded
  • 48. Sieve of Eratosthenes N 2 3 5 7 11 13
  • 49. CSP – Stackless – Primes import stackless def generate(ch): for i in range(2, 1000): ch.send(i) def pfilter(chin, chout, p): for i in chin: if i % p != 0: chout.send(i) def primes(chin): while 1: prime = chin.receive() print prime chout = stackless.channel() stackless.tasklet(pfilter)(chin, chout, prime) chin = chout c = stackless.channel() stackless.tasklet(generate)(c) stackless.tasklet(primes)(c) stackless.run()
  • 50. CSP – Stackless – Primes import stackless def generate(ch): for i in range(2, 1000): ch.send(i) def pfilter(chin, chout, p): for i in chin: if i % p != 0: chout.send(i) def primes(chin): while 1: prime = chin.receive() print prime chout = stackless.channel() stackless.tasklet(pfilter)(chin, chout, prime) chin = chout c = stackless.channel() stackless.tasklet(generate)(c) stackless.tasklet(primes)(c) stackless.run() N 2 P n P n+1
  • 51. CSP – Go – Primes func generate(ch chan int) { for i := 2; ; i++ { ch <- i } // Send 'i' to channel 'ch'. } func filter(in, out chan int, prime int) { for { i := <-in // Receive 'i' from 'in'. if i % prime != 0 { out <- i } // Send 'i' to 'out'. } } func main() { ch := make(chan int) // Create a new channel. go generate(ch) // Start generate() as a goroutine. for { prime := <-ch fmt.Println(prime) ch1 := make(chan int) go filter(ch, ch1, prime) ch = ch1 } } N 2 P n P n+1
  • 52.
  • 53. Locks
  • 55.
  • 56. Objects send, and respond to messages
  • 57. All code is written single threaded Note that the 'channels' are implicit
  • 58. Actors – IO – Primes Filter := Object clone Filter init := method(p, self prime := p self next := nil self ) Filter number := method(n, r := n % prime; if (r != 0, if (self next == nil, n println; next = self clone init(n) ) next @ number(n); yield ) ) Filter init(2) for (i, 2, 1000, Filter number(i); yield ) N 2 P n P n+1
  • 59. The path A short story, a book , design patterns, and Djikstra
  • 60.
  • 62. REST, MapReduce and other share-nothing architectures
  • 63. My Goal Every time you use a concurrency pattern you remember the lack of affordances , and it proves sufficiently irritating . The short story , the book , and design patterns .