Pages

Sunday, August 26, 2012

Use a martial arts principle to improve your Test Driven Development skills.


In ancient Japan, martial arts were not just defence techniques, they were also  a way of life(jap. budo”).
In this way of life they combined physical, moral and spiritual dimensions with the goal of self-improvement.

Since very young, Japanese kids would join a martial arts school, to study: karate, aikido, judo…  
They learned martial arts using a technique called “Kata”.

The “Kata” technique was based in the principle of “learn by repetition”.
By practicing exercises in a repetitive maner the learner  comes to a point where develops the ability to execute those exercises and movements in a natural and reflexive maner(“intuition”).

Today in software development the amount of trainers that recommend to use Test Driven Development Katas, is increasing.  Some would even say that the TDD katas, are the only way to learn TDD.  The original idea of the kata as a maner of learning software development was introduced by Dave Thomas(author of: The pragmatic Programmer: From Journey man to Master ).

Programming principles such as KISS(Keep It Simple and Stupid) or YAGNI(You Ain’t Gonna Need It ) are very common in the TDD philosophy, but the main mantra behind TDD is the RGR principle (Red, Green, Refactor).

From the theoretical point of view, the RGR principle seems often very simple to new TDD developers.
But when it comes to real life practice, in many occasions the complexity of the software can make less experienced developers to panic.

A great practice to avoid this is to practice a TDD kata once in a while.
Peter Norvost(author of the blog: Geek Noise), recommends to new TDD developers to do simple katas of 30 minutes every morning for 2 weeks. 
Now I will show you an example of a very simple TDD kata and then I will perform a demonstration.

KATA #1: THE STRING CALCULATOR (Kata description taken from: http://osherove.com/tdd-kata-1/)
1-An empty string returns zero
2-A single number returns the value
3-Two numbers, comma delimited, returns the sum
4-Two numbers, newline delimited, returns the sum
5-Three numbers, delimited either way, returns the sum
6-Negative numbers throw an exception
7-Numbers greater than 1000 are ignored



Note: Don't forget to set the quality to HD in the video player





Monday, August 13, 2012

Subversion Native Library Not Available

Did you ever have to deal with this annoying Subversion update message when Starting your Eclipse IDE?


To avoid it popping up, just go to your preferences and change the SVN interface.


Friday, August 10, 2012

Dynamic initialization of HashMap using double braces

Often we have to work with data structures like: Maps, Arrays,Sets...
And many times it is just more comfortable to initialize them dynamically.

In the following example i use double brace initialization technique to dynamically initialize a map that uses a constant as a key and a List as a value. When we want to initialize this types of structures in a dynamical way, this approach is probably the most comfortable and easy.


1:  new HashMap<ProductCategories, List<Products>>() {  
2:                 {  
3:                      put(ProductCategories.DAIRY_PRODUCTS,  
4:                                new ArrayList<Products>() {  
5:                                     {  
6:                                          add(Products.CHEESE);  
7:                                          add(Products.SOUR_CREAM);  
8:                                          add(Products.YOGURTH);  
9:                                     }  
10:                                 }  
11:                      );  
12:                      put(ProductCategories.MEAT,   
13:                                new ArrayList<Products>() {  
14:                                     {  
15:                                          add(Products.BEEF);  
16:                                          add(Products.CHICKEN);  
17:                                          add(Products.TURKEY);  
18:                                     }  
19:                                }  
20:                      );  
21:                      put(ProductCategories.VEGETABLES,   
22:                                new ArrayList<Products>() {  
23:                                     {  
24:                                          add(Products.TOMATO);  
25:                                          add(Products.ONION);  
26:                                          add(Products.CAGABE);  
27:                                     }  
28:                                }  
29:                      );  
30:                 }  
31:            };  

Share with your friends