Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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? Communicating Sequential Processes (CSP)
Actors The difference is only in 'what' is concurrent
CSP Model Based on CSP by C.A.R. Hoare.
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 An implementation could use: Threads
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.5
Oregon Law Practice Management
 
LoteríA Correcta
LoteríA CorrectaLoteríA Correcta
LoteríA Correcta
guest4dfcdf6
 
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 09
gshea11
 
Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1Paulo Freire Pedagpogia 1
Paulo Freire Pedagpogia 1
Alejandra 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
 
Digital Wish
Digital WishDigital Wish
Digital Wish
Terri Duchsherer
 
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 experiment
Amos Wenger
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
Ruth Marvin
 
Design problem
Design problemDesign problem
Design problem
Sanjay Kumar Chakravarti
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
Chui-Wen Chiu
 
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
 
name name2 n
name name2 nname name2 n
name name2 n
callroom
 
ppt30
ppt30ppt30
ppt30
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
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt30
ppt30ppt30
ppt30
 

Recently uploaded

Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Erasmo Purificato
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
Edge AI and Vision Alliance
 
HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)
Alpen-Adria-Universität
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
The Digital Insurer
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
crioux1
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
ScyllaDB
 
Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
Vijayananda Mohire
 
What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)
Margaret Fero
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
ScyllaDB
 
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum ThreatsNavigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
anupriti
 

Recently uploaded (20)

Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
 
HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024Verti - EMEA Insurer Innovation Award 2024
Verti - EMEA Insurer Innovation Award 2024
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
 
Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
 
What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
 
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum ThreatsNavigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
 

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. What are the concurrency models? Communicating Sequential Processes (CSP)
  • 42. Actors The difference is only in 'what' is concurrent
  • 43. CSP Model Based on CSP by C.A.R. Hoare.
  • 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. CSP An implementation could use: Threads
  • 53. Locks
  • 55. Actor Model Objects are concurrent
  • 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. Further Reading http://golang.org http://www.iolanguage.com/ http://www.stackless.com/ Things not mentioned Futures
  • 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 .