SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

Ήπειρος Αρχέγονος Ελλάς. Μέρος 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 Αναστήλωση των Αγίων Εικόνων και η...ΠΑΖΛ ΕΠΙΛΟΓΕΣ
 

En vedette (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 Αναστήλωση των Αγίων Εικόνων και η...
 

Similaire à 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 n
name name2 nname name2 n
name name2 ncallroom
 

Similaire à 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
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 

Dernier

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Dernier (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

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 .