SlideShare a Scribd company logo
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

More Related Content

What's hot

Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
amiable_indian
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
Mosky Liu
 
C# p5
C# p5C# p5
Python2 unicode-pt1
Python2 unicode-pt1Python2 unicode-pt1
Python2 unicode-pt1
abadger1999
 
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
Phoenix
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
Mr. Vikram Singh Slathia
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
Erin Dees
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
Mosky Liu
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
GlobalLogic 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 Anymore
Erin Dees
 
Python interview questions for experience
Python interview questions for experiencePython interview questions for experience
Python interview questions for experience
MYTHILIKRISHNAN4
 
MMBJ Shanzhai Culture
MMBJ Shanzhai CultureMMBJ Shanzhai Culture
MMBJ Shanzhai Culture
MobileMonday Beijing
 
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.com
Antonio 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 Petang
Imsamad
 

What's hot (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
 

Viewers also liked

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

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

Similar to 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 Python
Python Ireland
 
Python 3000
Python 3000Python 3000
Python 3000
Bob Chao
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
aeberspaecher
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
CodeOps Technologies LLP
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
Sigma Software
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
Amos 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_loops
Ruth Marvin
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 
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
jtdudley
 
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
Soham Kansodaria
 
ppt7
ppt7ppt7
ppt7
callroom
 
ppt2
ppt2ppt2
ppt2
callroom
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
ppt9
ppt9ppt9
ppt9
callroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
amiable_indian
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
callroom
 

Similar to 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
 
ppt9
ppt9ppt9
ppt9
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 

Recently uploaded

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

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 .