Programming Languages and their influence in Thinking

66
agile software development & services Los Lenguajes de Programación y su Impacto en el Pensamiento Hernán Wilkinson Twitter: @HernanWilkinson Blog: objectmodels.blogspot.com www.10pines.com

Transcript of Programming Languages and their influence in Thinking

Page 1: Programming Languages and their influence in Thinking

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

Page 2: Programming Languages and their influence in Thinking

The world “we live” in … ?

Page 3: Programming Languages and their influence in Thinking

The world “we live” in … ?

Page 4: Programming Languages and their influence in Thinking

The world “we live” in … ?

Page 5: Programming Languages and their influence in Thinking

The world “we live” in … ?

Page 6: Programming Languages and their influence in Thinking

Bret Victor - Thinking the unthinkable

Page 7: Programming Languages and their influence in Thinking

Language <-> Thinking

Page 8: Programming Languages and their influence in Thinking

What we can not talk about…we can not think about

(or it is difficult...)

Page 9: Programming Languages and their influence in Thinking

Do not Insist on English

Page 10: Programming Languages and their influence in Thinking

Aimara: Pasado y Futuro (nayra) (qhipa)

Page 11: Programming Languages and their influence in Thinking
Page 12: Programming Languages and their influence in Thinking

What is the relationship with Programming Languages?

(K. Iverson: “Notation as a tool of thought”1979 ACM Turing Award)

Page 13: Programming Languages and their influence in Thinking

If a programming language does not allow me to “TALK”

(write) about certain things

…Then I can not THINK

about certain solutions

Page 14: Programming Languages and their influence in Thinking

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;

Page 15: Programming Languages and their influence in Thinking

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 ;

Page 16: Programming Languages and their influence in Thinking

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?

Page 17: Programming Languages and their influence in Thinking

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 ;

Page 18: Programming Languages and their influence in Thinking

Code != Text

Page 19: Programming Languages and their influence in Thinking

How do we remove it?

Page 20: Programming Languages and their influence in Thinking

Technique:1. “Contextualize-Copy” the repeated

code to some “place”2. Parameterize what changes3. NAME IT!!!4. Use it :-)

Page 21: Programming Languages and their influence in Thinking

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 ;

Page 22: Programming Languages and their influence in Thinking

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?

Page 23: Programming Languages and their influence in Thinking

An object that represents “code”

Page 24: Programming Languages and their influence in Thinking

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)

Page 25: Programming Languages and their influence in Thinking

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

Page 26: Programming Languages and their influence in Thinking

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

Page 27: Programming Languages and their influence in Thinking

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!!

Page 28: Programming Languages and their influence in Thinking

Now… let’s do some reflection

Page 29: Programming Languages and their influence in Thinking

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”

Page 30: Programming Languages and their influence in Thinking

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!

Page 31: Programming Languages and their influence in Thinking

…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…

Page 32: Programming Languages and their influence in Thinking

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?

Page 33: Programming Languages and their influence in Thinking

Meta-Conclusion

Object = ¿Data + Code?

Page 34: Programming Languages and their influence in Thinking

Meta-Conclusion

Object = ¿Data + Code?

If you think so, you don´t understand OO yet

Page 35: Programming Languages and their influence in Thinking

Meta-Conclusion

Data is an ObjectCode is an Object

An Object is a “superior” concept that unifies data and

code

Page 36: Programming Languages and their influence in Thinking

What is the problem?

Page 37: Programming Languages and their influence in Thinking

No If!

Page 38: Programming Languages and their influence in Thinking

Now… let’s do some reflection

Page 39: Programming Languages and their influence in Thinking

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

Page 40: Programming Languages and their influence in Thinking

If as a message

Page 41: Programming Languages and their influence in Thinking
Page 42: Programming Languages and their influence in Thinking

A programming language is its creator's state of

knowledge

Page 43: Programming Languages and their influence in Thinking

timeToRun

Page 44: Programming Languages and their influence in Thinking

timeToRun

Page 45: Programming Languages and their influence in Thinking

timeToRun

Page 46: Programming Languages and their influence in Thinking

timeToRun

Page 47: Programming Languages and their influence in Thinking

timeToRun

Page 48: Programming Languages and their influence in Thinking

timeToRun

Page 49: Programming Languages and their influence in Thinking

timeToRun

Page 50: Programming Languages and their influence in Thinking

timeToRun

Page 51: Programming Languages and their influence in Thinking

Extending a Language!

Page 52: Programming Languages and their influence in Thinking

How can we add specific behavior to an object?

Let's see an example

Page 53: Programming Languages and their influence in Thinking

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?

Page 54: Programming Languages and their influence in Thinking

How do we learn a new word?

Page 55: Programming Languages and their influence in Thinking

Do we:1. Stop our brain2. “edit" a new definition in our

dictionary3. “Compile” the new definition4. Restart our brain?

Page 56: Programming Languages and their influence in Thinking

NO!!

Why do we have to do it with our programs?

Page 57: Programming Languages and their influence in Thinking

Can our programs “change while running”?

Can our programs “learn” as we learn?

Page 58: Programming Languages and their influence in Thinking

Yes, they can!... If they areMETACIRCULAR

Apply

Eval

Page 59: Programming Languages and their influence in Thinking

If we don’t have meta-circular languages, then we can not think about solutions that are natural in

our daily lives!!

Page 60: Programming Languages and their influence in Thinking

Let’s think again…

Are these concepts new?

Page 61: Programming Languages and their influence in Thinking

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”

Page 62: Programming Languages and their influence in Thinking

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

Page 63: Programming Languages and their influence in Thinking

Conclusions Learn other programming

languagesLisp/SchemeSmalltalkForth and more...

Learn our history

Page 64: Programming Languages and their influence in Thinking

"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!"

Page 65: Programming Languages and their influence in Thinking

Questions?

Page 66: Programming Languages and their influence in Thinking

agile software development & services

Muchas gracias!

[email protected]

twitter: @10Pines

Argentina

Tel.: +54 (11) 6091-3125Alem 693, 5B(1001) Buenos Aires