Software Project Health Check: Best Practices and Techniques for Your Product...
Programming Language Technical debt and their influence in Thinking and Desgin
1. The Technical Debt of the
Programming Languages
…
and the influence in our thinking
and designs
Hernán Wilkinson
Medellin 2014
agile software development & services
27. Meta Note: I repeated the
picture… I’m lacking an
abstraction or a better
image!
If we have repetition we are lacking
and abstraction… (an object in OO)
28. 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?
29. 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;
30. “Repeated code” does not mean
“repeated text”.
It means “repeated patterns of
collaboration”
34. Technique:
1. Copy the repeated code to some
“place”
2. Parameterize what changes
3. NAME IT!!!
4. Use it :-)
35. 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;
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: }
36. 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?
37. We need an abstraction to represent
“code”
We need a BLOCK or a CLOSURE…
… an object that represents “code”
38. Parameterize what changes
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 (aClosure.value(anObject) )
selected.add (anObject);
return selected:}
List<Account> selectedAccounts = new
ArrayList<Account> ();
for (Account account: accounts)
if (account.isOverdraw() )
selectedAccounts.add(account);
return selectedAccount;
39. 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;
40. 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;
41. Why not an Anonymous Class?
1. Sintax:
cutomers.select( customer => customber.nameStartsWith(“H”) )
customers.select( new SelectClosure<Customer> () {
public boolean value (Customer aCustomer) {
return aCustomer.nameStartsWith(“H”); }});
Which one reads better?
2. Binding problems…
42. 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!!
43. Now… let’s do some reflection
1. Why didn’t we see the
“duplicated code”?
2. Why didn’t we came
with a solution?
44. 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
45. 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
46. 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?
50. Try {
… do something
fail()
} catch (Exception e) {
assertTrue (…. ) }
self
TDD: Test for exceptions
should: [ do something ]
raise: Exception
withExceptionDo: [ :e | self assert: …. ] (Smallalk)
51. …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…
54. Mete-Conclusion
Data is an Object
Code is an Object
An Object is a “superior”
concept that unifies data and
code
55. 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?
70. How does impact our design a
language without extensible
classes?
ArrayHelper?? xxxManager??
71. How does impact our design a
language where we can not
see how it is implemented?
72. How can we add specific behavior to
an object?
Let's see an example
73. 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?
86. Why not having closures generate
debt?
Repeated code
Lack of abstractions
Difficult and costly to maintain
87. 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
88. 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
89. Conclusions
Learn other programming
languages
Lisp/Scheme
Smalltalk
Forth and more...
Learn our history
90. 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/