programming language technical debt and their influence in thinking and desgin

92
agile software development & services The Technical Debt of the Programming Languages and the influence in our thinking and designs Hernán Wilkinson Medellin 2014

Upload: hernan-wilkinson

Post on 01-Dec-2014

268 views

Category:

Software


1 download

DESCRIPTION

Presentation used at Avanet meetup, Medellin 2014

TRANSCRIPT

Page 1: Programming Language Technical debt and their influence in Thinking and Desgin

agile software development & services

The Technical Debt of the Programming Languages

…and the influence in our thinking

and designs

Hernán WilkinsonMedellin 2014

Page 2: Programming Language Technical debt and their influence in Thinking and Desgin

The world “we live” in … ?

Page 3: Programming Language Technical debt and their influence in Thinking and Desgin

The world “we live” in … ?

Page 4: Programming Language Technical debt and their influence in Thinking and Desgin

The world “we live” in … ?

Page 5: Programming Language Technical debt and their influence in Thinking and Desgin

The world “we live” in … ?

Page 6: Programming Language Technical debt and their influence in Thinking and Desgin

Bret Victor - Thinking the unthinkable

Page 7: Programming Language Technical debt and their influence in Thinking and Desgin

Language implies Thinking

Page 8: Programming Language Technical debt and their influence in Thinking and Desgin

Language implies Thinking

Thinking implies Language

Page 9: Programming Language Technical debt and their influence in Thinking and Desgin

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

(or it is difficult...)

Page 10: Programming Language Technical debt and their influence in Thinking and Desgin

Do not Insist on English

Page 11: Programming Language Technical debt and their influence in Thinking and Desgin

Aimara: Pasado y Futuro (nayra) (qhipa)

Page 12: Programming Language Technical debt and their influence in Thinking and Desgin

Languages without a concept for the future — "It rain tomorrow," instead of "It will rain tomorrow" — correlate

strongly with high savings rates.

Page 13: Programming Language Technical debt and their influence in Thinking and Desgin

Now, a design problemLet’s think about this:

How do we call the whole thing?

Page 14: Programming Language Technical debt and their influence in Thinking and Desgin

Let’s say Traffic Light (Semáforo)

How do we call each part?

Page 15: Programming Language Technical debt and their influence in Thinking and Desgin

Let’s say Traffic Regulator(guess why not 'Traffic Controller'?)

How do we call each Traffic Regulator in the Traffic Light context?

Page 16: Programming Language Technical debt and their influence in Thinking and Desgin

aTrafficLight

northSouthRegulator

eastWestRegulator

Page 17: Programming Language Technical debt and their influence in Thinking and Desgin

aTrafficLight

rightRegulator

leftRegulator

Page 18: Programming Language Technical debt and their influence in Thinking and Desgin

aTrafficLight

regulator1

regulator2

Page 19: Programming Language Technical debt and their influence in Thinking and Desgin

Not easy way to name them…Relative vs. Fix Coordinate System

B. Lee Whorf(Linguistic Relativity)

Page 20: Programming Language Technical debt and their influence in Thinking and Desgin

What is the relationship with Programming Languages?

(K. Iverson: “Notation as a tool of thought”)

Page 21: Programming Language Technical debt and their influence in Thinking and Desgin

If a programming language does not allow me to “TALK” (write) about certain

things…

Then I can not THINK about certain

solutions

Page 22: Programming Language Technical debt and their influence in Thinking and Desgin

ABSTRACTION

Page 23: Programming Language Technical debt and their influence in Thinking and Desgin

How do we refer to that “thing that has four wheels and moves?”

Page 24: Programming Language Technical debt and their influence in Thinking and Desgin

and to “that thing that moves and has four wheels?”

Page 25: Programming Language Technical debt and their influence in Thinking and Desgin

and to “that one that moves because it has

four wheels?”

Page 26: Programming Language Technical debt and their influence in Thinking and Desgin

To avoid REPETITIONTo provide MEANING to that

REPETITION

Page 27: Programming Language Technical debt and their influence in Thinking and Desgin

If we have repetition we are lacking and abstraction… (an object in OO)

Meta Note: I repeated the picture… I’m lacking an abstraction or a better image!

Page 28: Programming Language Technical debt and their influence in Thinking and Desgin

Let’s seeList<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add (customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

What is the problem?

Page 29: Programming Language Technical debt and their influence in Thinking and Desgin

We have repeated code!List<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add (customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

Page 30: Programming Language Technical debt and their influence in Thinking and Desgin

“Repeated code” does not mean “repeated text”.

It means “repeated patterns of collaboration”

Page 31: Programming Language Technical debt and their influence in Thinking and Desgin

What is the problem?

Page 32: Programming Language Technical debt and their influence in Thinking and Desgin

We are lacking an ABSTRACTION!

Repeated code means we are forgetting an object!

Page 33: Programming Language Technical debt and their influence in Thinking and Desgin

How do we remove it?

Page 34: Programming Language Technical debt and their influence in Thinking and Desgin

Technique:1. Copy the repeated code to some

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

Page 35: Programming Language Technical debt and their influence in Thinking and Desgin

Copy the repeated code to some placeList<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add(customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

class Collection<T> {

public Collection<T> <<NAME>> {

List<T> selected = new ArrayList<T> ();

for (T anObject: this )

if ( )

selected.add (anObject);

return selected: }

Page 36: Programming Language Technical debt and their influence in Thinking and Desgin

Parameterize what changes

List<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add (customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

How do we do it?

Page 37: Programming Language Technical debt and their influence in Thinking and Desgin

We need an abstraction to represent “code”

We need a BLOCK or a CLOSURE…… an object that represents “code”

Page 38: Programming Language Technical debt and their influence in Thinking and Desgin

Parameterize what changes

class Collection<T> {public Collection<T> <<NAME>> (Closure aClosure) {

List<T> selected = new ArrayList<T> ();

for (T anObject: this)

if (aClosure.value(anObject) )

selected.add (anObject);

return selected:}

List<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add(customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

Page 39: Programming Language Technical debt and their influence in Thinking and Desgin

NAME IT!!

class Collection<T> {public Collection<T> select (Closure aClosure) {

List<T> selected = new ArrayList<T> ();

for (T anObject: this)

if (aClosure.value(anObject) )

selected.add (anObject);

return selected:}

The most difficult part because it means that we understood the repeated code

meaning

List<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add(customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

Page 40: Programming Language Technical debt and their influence in Thinking and Desgin

List<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

selectedCustomers.add (customer);

return selectedCustomers;

List<Account> selectedAccounts = new ArrayList<Account> ();

for (Account account: accounts)

if (account.isOverdraw())

selectedAccounts.add(account);

return selectedAccount;

cutomers.select( customer => customer.nameStartsWith(“H”) )

accounts.select( account => account.isOverdraw() )

Page 41: Programming Language Technical debt and their influence in Thinking and Desgin

customers.select( new SelectClosure<Customer> () {

public boolean value (Customer aCustomer) {

return aCustomer.nameStartsWith(“H”); }});

cutomers.select( customer => customber.nameStartsWith(“H”) )

Why not an Anonymous Class?1. Sintax:

Which one reads better?

2. Binding problems…

Page 42: Programming Language Technical debt and their influence in Thinking and Desgin

What did we gain?1. Few words Simplicity, Easier to

understand, read, remember, etc. Less bugs!

2. We created a new “abstraction”: select

3. … and we remove duplicated code!!

Page 43: Programming Language Technical debt and their influence in Thinking and Desgin

Now… let’s do some reflection

1. Why didn’t we see the “duplicated code”?

2. Why didn’t we came with a solution?

Page 44: Programming Language Technical debt and their influence in Thinking and Desgin

Why didn’t we see the “duplicated code”

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

Page 45: Programming Language Technical debt and their influence in Thinking and Desgin

Why didn’t we see the “duplicated code”

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

Page 46: Programming Language Technical debt and their influence in Thinking and Desgin

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!

DOES NOT REALLY?

Page 47: Programming Language Technical debt and their influence in Thinking and Desgin

cutomers reject: [ :aCustomer | aCustomer nameStartsWith: ‘H’ ] (Smalltalk)

customers.reject { | aCustomer | aCustomer.nameStartsWith(“H”) } (Ruby)

customers.Where( aCustomer => !aCustomer.nameStarsWith(“H”)) (C#)

rejectList<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (!customer.nameStarsWith(“H”))

selectedCustomers.add (customer);

return selectedCustomers;

Page 48: Programming Language Technical debt and their influence in Thinking and Desgin

List<Customer> selectedCustomers = new ArrayList<Customer> ();

for (Customer customer: customers)

if (customer.nameStarsWith(“H”))

return customer;

throw ….

customers detect: [ :aCustomer | aCustomer nameStartsWith: ‘H’ ](Smalltalk)

customers.detect { | aCustomer | aCustomer.nameStartsWith(“H”) } (Ruby)

customers.First ( aCustomer => aCustomer.nameStarstWith(“H”)) (C#)

detect

Page 49: Programming Language Technical debt and their influence in Thinking and Desgin

customers collect: [ :aCustomer | aCustomer name ] (Smalltalk)

customers.collect { | aCustomer | aCustomer.name () } (Ruby)

customers.Select( aCustomer => aCustomer.name() ) (C#)

collectList<String> customerNames = new ArrayList<String> ();

for (Customer customer: customers)

customerNames.add (customer.name());

return customerNames;

Page 50: Programming Language Technical debt and their influence in Thinking and Desgin

self

should: [ do something ]

raise: Exception

withExceptionDo: [ :e | self assert: …. ] (Smallalk)

TDD: Test for exceptionsTry {

… do something

fail()

} catch (Exception e) {

assertTrue (…. ) }

Page 51: Programming Language Technical debt and their influence in Thinking and Desgin

…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 52: Programming Language Technical debt and their influence in Thinking and Desgin

Meta-Conclusion

Object = ¿Data + Code?

Page 53: Programming Language Technical debt and their influence in Thinking and Desgin

Meta-Conclusion

Object = ¿Data + Code?

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

Page 54: Programming Language Technical debt and their influence in Thinking and Desgin

Mete-Conclusion

Data is an Object

Code is an Object

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

code

Page 55: Programming Language Technical debt and their influence in Thinking and Desgin

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 56: Programming Language Technical debt and their influence in Thinking and Desgin

What is the problem?

Page 57: Programming Language Technical debt and their influence in Thinking and Desgin

No If!

Page 58: Programming Language Technical debt and their influence in Thinking and Desgin

If Implementation

“if” as a reserved word– What do we gain?– What do we loose?

“if” as a message– What do we gain?– What do we loose?

Page 59: Programming Language Technical debt and their influence in Thinking and Desgin

Boole’s Algebra

“if” as a message

Page 60: Programming Language Technical debt and their influence in Thinking and Desgin

Now… let’s do some reflection

1. Why didn’t we see the “polymorphic message”?

2. Why didn’t we came with a right solution?

Page 61: Programming Language Technical debt and their influence in Thinking and Desgin

Why didn’t we see the “polymorphic message”

Because 'if' as a reserved word does not make us think in polymorphism

Page 62: Programming Language Technical debt and their influence in Thinking and Desgin
Page 63: Programming Language Technical debt and their influence in Thinking and Desgin

How do we model 'age'?

Page 64: Programming Language Technical debt and their influence in Thinking and Desgin

How do we model 'Weight'?

Page 65: Programming Language Technical debt and their influence in Thinking and Desgin

How do we model 'money'?How do we model 'length'?How do we model 'speed'?

Page 66: Programming Language Technical debt and their influence in Thinking and Desgin

We need algebraic expressions

Let's see an example

Page 67: Programming Language Technical debt and their influence in Thinking and Desgin

Now… let’s do some reflection

1. Why don't we use algebraic expressions?

2. How does affect our design not to use them?

Page 68: Programming Language Technical debt and their influence in Thinking and Desgin

Because 'common programming languages' only provide arithmetic models

Because we don't realize that a language is the beginning not the end.

Page 69: Programming Language Technical debt and their influence in Thinking and Desgin

A programming language is its creator's state of knowledge

Page 70: Programming Language Technical debt and their influence in Thinking and Desgin

How does impact our design a language without extensible

classes?

ArrayHelper?? xxxManager??

Page 71: Programming Language Technical debt and their influence in Thinking and Desgin

How does impact our design a language where we can not see how it is implemented?

Page 72: Programming Language Technical debt and their influence in Thinking and Desgin

How can we add specific behavior to an object?

Let's see an example

Page 73: Programming Language Technical debt and their influence in Thinking and Desgin

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 74: Programming Language Technical debt and their influence in Thinking and Desgin

How do we learn a new word?

Page 75: Programming Language Technical debt and their influence in Thinking and Desgin

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

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

Page 76: Programming Language Technical debt and their influence in Thinking and Desgin

NO!!

Why do we have to do it with our programs?

Page 77: Programming Language Technical debt and their influence in Thinking and Desgin

Can our programs “change while running”?

Can our programs “learn” as we learn?

Page 78: Programming Language Technical debt and their influence in Thinking and Desgin

Yes, they can!... If they areMETACIRCULAR

Apply

Eval

Page 79: Programming Language Technical debt and their influence in Thinking and Desgin

Let’s see a problem:Can you make a proxy “learn” about its

proxee as it is used?

Page 80: Programming Language Technical debt and their influence in Thinking and Desgin

If we don’t have meta-circular languages, then we can not think

about solutions where meta-programming would fit!

Page 81: Programming Language Technical debt and their influence in Thinking and Desgin

Let’s think again…

Are these concepts new?

Page 82: Programming Language Technical debt and their influence in Thinking and Desgin

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 83: Programming Language Technical debt and their influence in Thinking and Desgin

Even More! Static vs. Dynamic typing

languages?Design?TDD?

Frameworks?Relational Databases?Web applications?

Page 84: Programming Language Technical debt and their influence in Thinking and Desgin

Fuente: http://c2.com/cgi/wiki?WardExplainsDebtMetaphor

Technical Deb Metaphor…

Page 85: Programming Language Technical debt and their influence in Thinking and Desgin
Page 86: Programming Language Technical debt and their influence in Thinking and Desgin

Why not having closures generate debt?

Repeated code Lack of abstractions Difficult and costly to maintain

Page 87: Programming Language Technical debt and their influence in Thinking and Desgin

Why not having meta-programming generate debt?

Some problems are more difficult to solve More code!

Programs can not reason about programs or themselves

We always need a programmer to do something a program could do

Page 88: Programming Language Technical debt and their influence in Thinking and Desgin

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

Page 89: Programming Language Technical debt and their influence in Thinking and Desgin

Conclusions Learn other programming

languages Lisp/Scheme Smalltalk Forth and more...

Learn our history

Page 90: Programming Language Technical debt and their influence in Thinking and Desgin

We teach this and other important design aspects in our courses

• OO Design I & OO Design II• TDD & Advanced TDD

Check them out at:http://www.10pines.com/

Page 91: Programming Language Technical debt and their influence in Thinking and Desgin

Questions?

Page 92: Programming Language Technical debt and their influence in Thinking and Desgin

agile software development & services

Muchas gracias!

[email protected]

twitter: @10Pines

Argentina

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