programming languages and their influence in thinking
TRANSCRIPT
agile software development & services
Los Lenguajes de Programación y su Impacto
en el Pensamiento
Hernán Wilkinson
Twitter: @HernanWilkinsonBlog: objectmodels.blogspot.com
www.10pines.com
The world “we live” in … ?
The world “we live” in … ?
The world “we live” in … ?
The world “we live” in … ?
Bret Victor - Thinking the unthinkable
Language <-> Thinking
What we can not talk about…we can not think about
(or it is difficult...)
Do not Insist on English
Aimara: Pasado y Futuro (nayra) (qhipa)
What is the relationship with Programming Languages?
(K. Iverson: “Notation as a tool of thought”1979 ACM Turing Award)
If a programming language does not allow me to “TALK”
(write) about certain things
…Then I can not THINK
about certain solutions
Let’s seeLi st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;f or ( Cust omer cust omer : cust omer s)
i f ( cust omer . nameSt ar sWi t h( “ H” ) )sel ect edCust omer s. add ( cust omer ) ;
r et ur n sel ect edCust omer s;
Let’s seeLi st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;f or ( Cust omer cust omer : cust omer s)
i f ( cust omer . nameSt ar sWi t h( “ H” ) )sel ect edCust omer s. add ( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;f or ( Account account : account s)
i f ( account . i sOver dr aw( ) )sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
Let’s seeLi st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;f or ( Cust omer cust omer : cust omer s)
i f ( cust omer . nameSt ar sWi t h( “ H” ) )sel ect edCust omer s. add ( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;f or ( Account account : account s)
i f ( account . i sOver dr aw( ) )sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
What is the problem?
We have repeated code!Li st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;f or ( Cust omer cust omer : cust omers )
i f ( cust omer. nameSt arsWi t h(“H”) )sel ect edCust omer s. add ( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;f or ( Account account : account s )
i f ( account . i sOverdraw() )sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
Code != Text
How do we remove it?
Technique:1. “Contextualize-Copy” the repeated
code to some “place”2. Parameterize what changes3. NAME IT!!!4. Use it :-)
c l ass Col l ect i on<T> {
publ i c Col l ect i on<T> <<NAME>> ( ? ) {
Li st <T> sel ect ed = new Ar r ayLi st <T> ( ) ;f or ( T anObj ect : t hi s )
i f ( )sel ect ed. add ( anObj ect ) ;
r et ur n sel ect ed: }
this
Copy the repeated code to some placeLi st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;
f or ( Cust omer cust omer : cust omers )
i f ( cust omer. nameSt arsWi t h(“H”) )
sel ect edCust omer s. add( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;
f or ( Account account : account s )
i f ( account . i sOverdraw() )
sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
Parameterize what changes
Li st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;f or ( Cust omer cust omer : cust omer s)
i f ( cust omer. nameSt arsWi t h(“H”) )sel ect edCust omer s. add ( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;f or ( Account account : account s)
i f ( account . i sOverdraw() )sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
How do we do it?
An object that represents “code”
c l ass Col l ect i on<T> {
publ i c Col l ect i on<T> <<NAME>> ( Cl osure aCl osure) {
Li st <T> sel ect ed = new Ar r ayLi st <T> ( ) ;f or ( T anObj ect : t hi s )
i f ( )sel ect ed. add ( anObj ect ) ;
r et ur n sel ect ed: }
this
Copy the repeated code to some placeLi st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;
f or ( Cust omer cust omer : cust omers )
i f ( cust omer. nameSt arsWi t h(“H”) )
sel ect edCust omer s. add( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;
f or ( Account account : account s )
i f ( account . i sOverdraw() )
sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
aClosure.execute(anObject)
c l ass Col l ect i on<T> {
publ i c Col l ect i on<T> sel ect ( Cl osure aCl osure) {
Li st <T> sel ect ed = new Ar r ayLi st <T> ( ) ;f or ( T anObj ect : t hi s )
i f ( )sel ect ed. add ( anObj ect ) ;
r et ur n sel ect ed: }
self
NAME IT!Li st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;
f or ( Cust omer cust omer : cust omers )
i f ( cust omer. nameSt arsWi t h(“H”) )
sel ect edCust omer s. add( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;
f or ( Account account : account s )
i f ( account . i sOverdraw() )
sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
aClosure.execute(anObject)
The most difficult part because it means that we understood the repeated code
meaning
Li st <Cust omer > sel ect edCust omer s = new Ar r ayLi st <Cust omer > ( ) ;f or ( Cust omer cust omer : cust omer s)
i f ( cust omer . nameSt ar sWi t h( “ H” ) )sel ect edCust omer s. add ( cust omer ) ;
r et ur n sel ect edCust omer s;
Li st <Account > sel ect edAccount s = new Ar r ayLi st <Account > ( ) ;f or ( Account account : account s)
i f ( account . i sOver dr aw( ) )sel ect edAccount s. add( account ) ;
r et ur n sel ect edAccount ;
cut omer s. sel ect ( cust omer - > cust omer . nameSt ar t sWi t h( “ H” ) )
account s. sel ect ( account - > account . i sOver dr aw( ) )
What did we gain?1. Few words Simplicity, Easier to
understand, read, remember, etc. Less bugs!
2. We created a new “abstraction”: select (filter in Java 8)
3. … and we removed duplicated code!!
Now… let’s do some reflection
1. Because we are use to that code (is the programming language the problem or us?)
2. Because there is no “concept” to remove it
Why didn’t we see the “duplicated code”
Why didn’t we came with a solution?
1. Because the programming language does not provide us with a “concept” to think about a solution!
…and much much more….
Imagine how your designs would be if
you could use closures
You can create your own control flow “sintax”
Further reading: LAMBDA The Ultimate…
Hamming / Closure
If there are certain objects that can not be created in some languages …
… and given the solutions provided by some programming languages…
The statement: “There are design solutions that are unthinkable in some
programming languages” ¿Does it surprise you?
Meta-Conclusion
Object = ¿Data + Code?
Meta-Conclusion
Object = ¿Data + Code?
If you think so, you don´t understand OO yet
Meta-Conclusion
Data is an ObjectCode is an Object
An Object is a “superior” concept that unifies data and
code
What is the problem?
No If!
Now… let’s do some reflection
Why did we not see the “polymorphic message”?
Because 'if' as a reserved word is a “primitive construction”, there is nothing behind it
Therefore it does not make us think in polymorphism
If as a message
A programming language is its creator's state of
knowledge
timeToRun
timeToRun
timeToRun
timeToRun
timeToRun
timeToRun
timeToRun
timeToRun
Extending a Language!
How can we add specific behavior to an object?
Let's see an example
Now… let’s do some reflection
1. What are the solutions we lack due to limited meta programming?
2. What do we loose if we do not have a meta-circular language?
How do we learn a new word?
Do we:1. Stop our brain2. “edit" a new definition in our
dictionary3. “Compile” the new definition4. Restart our brain?
NO!!
Why do we have to do it with our programs?
Can our programs “change while running”?
Can our programs “learn” as we learn?
Yes, they can!... If they areMETACIRCULAR
Apply
Eval
If we don’t have meta-circular languages, then we can not think about solutions that are natural in
our daily lives!!
Let’s think again…
Are these concepts new?
Lisp
John McCarthy
Alan Kay
“We must know our historyif we don’t want to reinvent… not only the tire, but a a flat tire”
Conclusions Do not accept languages without
Closures Do not accept languages without
good meta-programming Create your own extensions! Liberate yourself from the
programming language and frameworks
Conclusions Learn other programming
languagesLisp/SchemeSmalltalkForth and more...
Learn our history
"The Humble Programmer”E. Dijkstra
“The tools we are trying to use and the language or notation we are using to express or record our thoughts, are the major factors determining what we can think or express at all!"
Questions?
agile software development & services
Muchas gracias!
twitter: @10Pines
Argentina
Tel.: +54 (11) 6091-3125Alem 693, 5B(1001) Buenos Aires