Software Illusion

Code talks

Well, what can I say?

Enjoy the week ;-)
The music is not related to the post, but I was listening to it yesterday so here it goes Long Before Rock 'N' Roll, from Mando Diao.



Here is the link to the webcast: Busting the Myths of Agile Development: What People Are Really Doing.
Have a nice week!
NEWTON: As a nerd, I want to be cool having the possibility to have a specific night for a specific day.
I can have a night for a specific day that differs from the normal night for that day of the week. It is a special night occasion.
PASCAL: As a friend of a nerd, I want to know when a night happens.
Based on the name of the night I want to know when it happens.
Based on the day of the week I want to know what is the night of that day <(I don't want to avoid those nerd guys)>.
I want to know which night of a specific day.
public interface NightService {
/**
* Add a new night to the store. If the night is supplied with an ID it will be replaced.
* After the call to the registerNight method the Night object will have the ID filled.
* @param night night to be added.
*/
public void registerNight(Night night);
/**
* Replace the night stored. The provided night should have the id filled in order
* to have the date replaced correct.
* @param night night to be replaced.
*/
public void changeNight(Night night);
/**
* Returns the night by its unique identifier
* @param nightId identifier of the night.
* @return
* Night object, null if there isn't any night for that id.
*/
public Night findById(String nightId);
/**
* Returns the list of nights of the specified day of week.
*
*- The order returned by the find week day should be from the first include to the last one.
*
* @param dayOfWeek
* @return null when there isn't any night for the specified day of week, otherwise a list with the nights.
*/
public List<Night> findWeekDayNights(DayOfWeek dayOfWeek);
/**
* Returns the list of nights of the specified name, the name match is not case sensitive.
*
*- The order returned should be from the first include to the last one.
*
* @param dayOfWeek
* @return null when there isn't any night for the specified name, otherwise a list with the nights.
*/
public List<Night> findNightWithName(String nightName);
/**
* Returns the corresponding night for a specific day.
* @param date date of the night
* @return
* Night corresponding to the date, if there isn't any night for that day then returns null.
*/
public Night nightOf(Date date);
}
public class NightServiceTest {
private NightService nightService = null;
private TestUtils testUtils = null;
//... Code removed for simplicity
@Test
public void testRegisterNight() {
Night movieNight = testUtils.createNight(DayOfWeek.MONDAY, "MOVIE_NIGHT");
nightService.registerNight(movieNight);
Night movieNightRead = nightService.findById(movieNight.getId());
assertEquals(movieNight, movieNightRead);
}
@Test
public void testChangeNight() {
Night gameNight = testUtils.createNight(DayOfWeek.TUESDAY, "GAME_NIGHT");
nightService.registerNight(gameNight);
gameNight.setName("Man this is the really the GAME night");
nightService.changeNight(gameNight);
Night gameNightRead = nightService.findById(gameNight.getId());
assertEquals(gameNight, gameNightRead);
}
@Test
public void testFindNightById() {
Night wOwNight = testUtils.createNight(DayOfWeek.WEDNESDAY, "WOW_NIGHT");
nightService.registerNight(wOwNight);
String validId = wOwNight.getId();
String invalidId = "invalidId";
Night validNight = nightService.findById(validId);
assertNotNull(validNight);
assertEquals(validId, validNight.getId());
Night invalidNight = nightService.findById(invalidId);
assertNull(invalidNight);
}
@Test
public void testFindWeekDayNights() {
//Create the nights
Night bownlingNight = testUtils.createNight(DayOfWeek.FRIDAY, "BOWNLING NIGHT");
Night arcadeNight = testUtils.createNight(DayOfWeek.FRIDAY, "ARCADE NIGHT");
Night kartNight = testUtils.createNight(DayOfWeek.FRIDAY, "KART NIGHT");
Night pizzaNight = testUtils.createNight(DayOfWeek.THURSDAY, "PIZZA NIGHT");
nightService.registerNight(bownlingNight);
nightService.registerNight(arcadeNight);
nightService.registerNight(kartNight);
nightService.registerNight(pizzaNight);
List<Night> mondayNights = nightService.findWeekDayNights(DayOfWeek.MONDAY);
List<Night> tuesdayNights = nightService.findWeekDayNights(DayOfWeek.TUESDAY);
List<Night> wednesdayNights = nightService.findWeekDayNights(DayOfWeek.WEDNESDAY);
List<Night> thursdayNights = nightService.findWeekDayNights(DayOfWeek.THURSDAY);
List<Night> fridayNights = nightService.findWeekDayNights(DayOfWeek.FRIDAY);
List<Night> saturdayNights = nightService.findWeekDayNights(DayOfWeek.SATURDAY);
List<Night> sundayNights = nightService.findWeekDayNights(DayOfWeek.SUNDAY);
assertNull(mondayNights);
assertNull(tuesdayNights);
assertNull(wednesdayNights);
assertNotNull(thursdayNights);
assertNotNull(fridayNights);
assertNull(saturdayNights);
assertNull(sundayNights);
assertEquals(thursdayNights.size(), 1);
assertEquals(fridayNights.size(), 2);
assertEquals(pizzaNight, thursdayNights.get(0));
//The order returned by the find week day should be from the first include to the last one.
assertEquals(bownlingNight, fridayNights.get(0));
assertEquals(arcadeNight, fridayNights.get(1));
assertEquals(kartNight, fridayNights.get(2));
}
@Test
public void testFindNightWithName() {
Night surprise_Surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "SURPRISE SURPRISE NIGHT");
Night big_Surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "BIG SURPRISE NIGHT");
Night surprise_surprise_Night = testUtils.createNight(DayOfWeek.MONDAY, "suprise surprise NIGHT");
Night double_Night_one = testUtils.createNight(DayOfWeek.TUESDAY, "DOUBLE NIGHT");
Night double_Night_two = testUtils.createNight(DayOfWeek.TUESDAY, "DOUBLE NIGHT");
nightService.registerNight(surprise_Surprise_Night);
nightService.registerNight(big_Surprise_Night);
nightService.registerNight(surprise_surprise_Night);
nightService.registerNight(double_Night_one);
nightService.registerNight(double_Night_two);
List<Night> nightsRead = nightService.findNightWithName("SURPRISE");
assertNull(nightsRead);
nightsRead = nightService.findNightWithName("SURPRISE NIGHT");
assertNull(nightsRead);
nightsRead = nightService.findNightWithName("SURPRISE SURPRISE");
assertNull(nightsRead);
nightsRead = nightService.findNightWithName("SURPRISE SURPRISE NIGHT");
assertEquals(nightsRead.get(0), surprise_Surprise_Night);
assertFalse(nightsRead.get(0).equals(big_Surprise_Night));
assertFalse(nightsRead.get(0).equals(surprise_surprise_Night));
nightsRead = nightService.findNightWithName("BIG SURPRISE NIGHT");
assertFalse(nightsRead.get(0).equals(surprise_Surprise_Night));
assertEquals(nightsRead.get(0), big_Surprise_Night);
assertFalse(nightsRead.get(0).equals(surprise_surprise_Night));
nightsRead = nightService.findNightWithName("suprise surprise NIGHT");
assertFalse(nightsRead.get(0).equals(surprise_Surprise_Night));
assertFalse(nightsRead.get(0).equals(big_Surprise_Night));
assertEquals(nightsRead.get(0),surprise_surprise_Night);
nightsRead = nightService.findNightWithName("DOUBLE NIGHT");
assertEquals(nightsRead.size(), 2);
assertEquals(nightsRead.get(0), double_Night_one);
assertEquals(nightsRead.get(1), double_Night_two);
}
@Test
public void testNightOf() {
//24.12.2010 is a friday
//29.02.2012 is a wednesday
//15.05.2010 is saturday
//22.05.2010 is saturday
Night gameNight = testUtils.createNight(DayOfWeek.FRIDAY, "GAME NIGHT");
Night thaiFoodNight = testUtils.createNight(DayOfWeek.WEDNESDAY, "THAI FOOD NIGHT");
Night feverNight = testUtils.createNight(DayOfWeek.SATURDAY, "FEVER NIGHT");
nightService.registerNight(gameNight);
nightService.registerNight(thaiFoodNight);
nightService.registerNight(feverNight);
Calendar _15_05_2010 = Calendar.getInstance();
_15_05_2010.set(Calendar.DAY_OF_MONTH, 15);
_15_05_2010.set(Calendar.MONTH, Calendar.MAY);
_15_05_2010.set(Calendar.YEAR, 2010);
Calendar _22_05_2010 = Calendar.getInstance();
_22_05_2010.set(Calendar.DAY_OF_MONTH, 22);
_22_05_2010.set(Calendar.MONTH, Calendar.MAY);
_22_05_2010.set(Calendar.YEAR, 2010);
Calendar _24_12_2010 = Calendar.getInstance();
_24_12_2010.set(Calendar.DAY_OF_MONTH, 24);
_24_12_2010.set(Calendar.MONTH, Calendar.DECEMBER);
_24_12_2010.set(Calendar.YEAR, 2010);
Calendar _29_02_2012 = Calendar.getInstance();
_29_02_2012.set(Calendar.DAY_OF_MONTH, 29);
_29_02_2012.set(Calendar.MONTH, Calendar.FEBRUARY);
_29_02_2012.set(Calendar.YEAR, 2012);
Night night_24_12_2010 = nightService.nightOf(_24_12_2010.getTime());
Night night_29_02_2012 = nightService.nightOf(_29_02_2012.getTime());
Night night_15_05_2010 = nightService.nightOf(_15_05_2010.getTime());
Night night_22_05_2010 = nightService.nightOf(_22_05_2010.getTime());
assertEquals(gameNight, night_24_12_2010);
assertEquals(thaiFoodNight, night_29_02_2012);
assertEquals(feverNight, night_15_05_2010);
assertEquals(feverNight, night_22_05_2010);
}
}
Let's imagine a group of geek-nerd-friends, every week day they do something during the night. They have the Halo night, the comic store night, the movie night and so on, a full life. Because of that one of those guys wants to manage the nights, they want to know for each night: the participants, the activities of each one, time of those activites, how much people are involved in each activity and which nice widgets they have to use for those activities.
PYTHAGORAS: As a nerd, I want to organize the night and distribute the activities of that night across all my nerd friends.
- All the nights have a name, like Halo night or Comic store night.
- It always happens in a specific day of the week, like Halo night is always on wednesday.
- To have a nice night we should execute a group of activities (buy food, bring the game, etc).
- Each activity has one responsible.
- Each activity could need the help of 1 or more people.
- Each activity could require one or more widget to be executed (using the iPhone to find the pizza store, the teleport machine to arrive in time, etc).
- Each activity should be done to have a nice night.
- A night is ready to start when all the activities are done.

@Test
public void testIsNightReady() {
Night saturdayNightFever = new Night();
saturdayNightFever.setDayOfWeek(DayOfWeek.SATURDAY);
saturdayNightFever.setName("Saturday Night Fever revival night!");
//No activities means that the night is read to start
assertTrue(saturdayNightFever.isNightReady());
//Let's add a list of activities in the night
List<Activity> activitiesOfTheNight = new ArrayList<Activity>();
saturdayNightFever.setActivityList(activitiesOfTheNight);
assertTrue(saturdayNightFever.isNightReady());
//For a saturday night fever we need to practive dance listening the BeeGees K7
Activity practiceDance = new Activity();
practiceDance.setWhatShouldBeDone("Dance listening BeeGees K7");
practiceDance.setResponsible("me");
saturdayNightFever.getActivityList().add(practiceDance);
//And also get the nice white suite
Activity takeTheSuite = new Activity();
takeTheSuite.setWhatShouldBeDone("Take the white suite at mother's house");
takeTheSuite.setResponsible("me");
saturdayNightFever.getActivityList().add(takeTheSuite);
//And finally meet the girl
Activity meetTheGirl = new Activity();
meetTheGirl.setWhatShouldBeDone("Meet the girl at his house");
meetTheGirl.setResponsible("me");
saturdayNightFever.getActivityList().add(meetTheGirl);
//I have done none activity, so the night is not ready to start
assertFalse(saturdayNightFever.isNightReady());
//I've found the K7 and danced a lot, but still not ready.
practiceDance.setDone(true);
assertFalse(saturdayNightFever.isNightReady());
//Got the old father's white suite at moms house
takeTheSuite.setDone(true);
assertFalse(saturdayNightFever.isNightReady());
//Meet the girl
meetTheGirl.setDone(true);
//Now it is time to ROCK
assertTrue(saturdayNightFever.isNightReady());
}
The point here is: nice tools help but do not solve our problems and the same time that short iterations, real scope review, communication, real information that serves as input for the work, test cases and other stuffs that makes the big wheel turn helps much more.
In a more philosophical way of thinking: a beautiful ring (the tool) is still just a ring without a gentle hand (the process) to have it, and I can imagine much more uses for a gentle hand than to a ring.







I need a hero
…
He’s gotta be strong
And he’s gotta be fresh from the fight
…
He’s gotta be sure
And it’s gotta be soon
And he’s gotta be larger than life
Somewhere after midnight
…- I need a hero "Bonnie Tyler"
Who's gonna tell you when,A ever standing request in the list?
It's too late,
…
You can't go on, thinkin',
Nothings' wrong, but bye
…- Driver "The cars"
Its my own designA new incredible "never-ever-though" feature rises
...
I can't stand this indecision
Married with a lack of vision- Everybody Wants to Rule the World "Tears for fears"
What is it good forA good UI interface
Absolutely nothing
Say it again
...
What is it good for
Absolutely nothing- War "Edwin Starr"
More than just blind ambitionTrying to avoid that 90 degrees change on the project
More than just simple greed
More than just a finish line
...
Like a streak of lightning
That flashes and fades
...
More than high performance
More than just a spark
More than just the bottom line
...- Marathon "Rush"
But it's gonna take money
A whole lotta spending money
Its gonne take plenty of money
To do it right child
Its gonna take time
A whole lot of precious time
Its gonna take patience and time, ummm
To do it, to do it, to do it, to do it, to do it,
To do it right child
...- Got my mind set on you "George Harrison"
create procedure PP_TODAY
as
begin
select today=convert(char(10),getdate(),103)
end
create procedure PP_HOUR
as
begin
select hour=convert(varchar,getdate(),103) + " " + convert(varchar,getdate(),108)
end
I am new at Ruby development and I AM not sure that it could solve the Global Warning problems, but it could be a nice to tool to have in your pocket.
For example, yesterday I needed to extract some data from a bulk of files, so I created a one shoot script that help me a lot.
I will not post here the script that I created, it will not help anyone but I will write down a Ruby roadmap, if you are a beginner it could help. First of all we need to understand that Ruby is just a language, it is not related to web stuffs or things like that; but now you come as say: “But my little friend said that Ruby is a boost for web application, you are a liar, your… your.. fool!”
Take easy little boy, I will explain it to you: the magical word for web is Ruby on Rails. But what is it? Rails is the underline framework for Ruby that makes web development easier, because of the conventions that it is based on.
First step you should go to the website: Ruby on Rails, go directly to the Get Started. There you will be able to download the Ruby and get the instructions to install the Rails, I recommend that you install both (it doesn’t matter if you are going to do scripts or web development).
Once you get your environment running make the first application (suggested at the Get Started), after that you should make a difficult decision: learn the language or keep running in a nice tutorial. I am for make a nice tutorial, but I will let you choose:
· Learn language: This is the most crazy book for programming language that I have seen so far, but it worth a look: why's (poignant) guide to Ruby. It will give you a nice overview of the Ruby language, there isn’t any web reference here.
· Tutorial: there is plenty tutorials about Ruby on Rails in the internet, but I suggest these: Getting Started With Rails, Tutorial Step One (wiki). The last one is more direct, although the text is a little bit confusing.
I think that it is a little bit amount of data to start with Ruby. Just move yourself little boy and start learning it, next I am going to post a Ruby script to create fixed file size for testing.
base.setAttribute(ATTRIBUTE); |