1. La Influencia de Java en
Nuestra Manera de Pensar
Hernán Wilkinson
Twitter: @HernanWilkinson
Blog: objectmodels.blogspot.com
www.10pines.com
agile software development & services
12. What is the relationship with
Programming Languages?
(K. Iverson: “Notation as a tool of thought”
1979 ACM Turing Award)
13. If a programming
language does not
allow me to “TALK”
(write) about certain
things
…
Then I can not THINK
about certain
solutions
14. Let’s see
List<Customer> selectedCustomers = new ArrayList<Customer> ();
for (Customer customer: customers)
if (customer.nameStarsWith(“H”))
selectedCustomers.add (customer);
return selectedCustomers;
15. Let’s see
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;
16. Let’s see
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;
What is the problem?
17. 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;
21. Copy the repeated code to some place
List<Customer> selectedCustomers =
new ArrayList<Customer> ();
for (Customer customer: customers)
if (customer.nameStarsWith(“H”))
selectedCustomers.add(customer);
return selectedCustomers;
class Collection<T> {
public Collection<T> <<NAME>> (?) {
List<T> selected = new ArrayList<T> ();
for (T anObject: this )
if ( )
selected.add (anObject);
return selected: }
this
List<Account> selectedAccounts = new
ArrayList<Account> ();
for (Account account: accounts)
if (account.isOverdraw())
selectedAccounts.add(account);
return selectedAccount;
22. 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?
24. Copy the repeated code to some place
List<Customer> selectedCustomers =
new ArrayList<Customer> ();
for (Customer customer: customers)
if (customer.nameStarsWith(“H”))
selectedCustomers.add(customer);
return selectedCustomers;
class Collection<T> {
public Collection<T> <<NAME>> (Closure aClosure) {
List<T> selected = new ArrayList<T> ();
for (T anObject: this )
if ( )
selected.add (anObject);
return selected: }
this
List<Account> selectedAccounts = new
ArrayList<Account> ();
for (Account account: accounts)
if (account.isOverdraw())
selectedAccounts.add(account);
return selectedAccount;
aClosure.execute(anObject)
25. class Collection<T> {
public Collection<T> select (Closure aClosure) {
List<T> selected = new ArrayList<T> ();
for (T anObject: this )
if ( )
selected.add (anObject);
return selected: }
self
NAME IT!
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;
aClosure.execute(anObject)
The most difficult
part because it
means that we
understood the
repeated code
meaning
26. List<Customer> selectedCustomers = new ArrayList<Customer> ();
for (Customer customer: customers)
if (customer.nameStarsWith(“H”))
selectedCustomers.add (customer);
return selectedCustomers;
cutomers.select( customer -> customer.nameStartsWith(“H”) )
accounts.select( account -> account.isOverdraw() )
List<Account> selectedAccounts = new ArrayList<Account> ();
for (Account account: accounts)
if (account.isOverdraw())
selectedAccounts.add(account);
return selectedAccount;
27. Why not an Anonymous Class?
1. Sintax:
cutomers.select( customer -> customber.nameStartsWith(“H”) )
customers.select( new Condition<Customer> () {
public boolean value (Customer aCustomer) {
return aCustomer.nameStartsWith(“H”); }});
Which one reads better?
2. Binding problems…
28. 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!!
29. Now… let’s do some reflection
1. Why didn’t we see the
“duplicated code”?
2. Why didn’t we came
with a solution?
30. 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
31. 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!
32. Try {
… do something
fail()
} catch (Exception e) {
assertTrue (…. ) }
self
TDD: Test for exceptions
should: [ do something ]
raise: Exception
withExceptionDo: [ :e | self assert: …. ] (Smallalk)
33. …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…
36. Mete-Conclusion
Data is an Object
Code is an Object
An Object is a “superior”
concept that unifies data and
code
37. 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?
41. 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?
42. 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
53. How can we add specific behavior to
an object?
Let's see an example
54. 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?
63. Lisp
John McCarthy
Alan Kay
“We must know our history
if we don’t want to reinvent
… not only the tire, but a
a flat tire”
64. And more…
Classes are modules
Static is not OO
Misleading words:
this
extends
Unnecessary implementation complexity
filter, map, etc.
65. 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
66. Conclusions
Learn other programming
languages
Lisp/Scheme
Smalltalk
Forth and more...
Learn our history
67. "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!"
68. Alan Kay
"Java and C++ make you think that
the new ideas are like the old
ones. Java is the most distressing
thing to hit computing since MS-DOS.“