Nov 30 2009

Astonishing

Category: presentationgiordano scalzo @ 10:27 am

I believe Ted is a place full of wonderful and inspiring things.
Take a look to this:

Technorati Tags: ,

Tags: ,


Nov 18 2009

Italian Agile Day is coming

Category: agile,megiordano scalzo @ 4:23 pm


It’s near the end of November, it’s Italian Agile Day time.
As each year, it’s the time to gather all Italian Agile Practitioners, or wannabe-Agile, for a community day.
The site is the nice Hotel Savoia Regency in Bologna.
As usual, the timetable is very interesting, and I still haven’t decided what conferences attend: I’ll float around and I’ll make gut decisions.

See you, there!

Technorati Tags: ,

Tags: ,


Nov 12 2009

Using Google Wave as learning tool

Category: rubygiordano scalzo @ 2:53 pm


Google Wave is live since early October, but still it seems “empty”: it lacks functionalities, users and goals.

After Wave was launched, first Twitter-sphere was full of “I need a Wave account!!! then of “I’m on Wave, what can I do?”.
Maybe Google Wave is so new that is difficult to understand, or maybe is a big flop: only time will give us an answer.

Anyway, something is moving.
Satish Talim, of Rubylearning fame, just started an experimental course to JRuby using Google Wave.

Currently only two chapters have been published, and the course seems not much different from an email or web based course; neverthless I think it’s an interesting experiment and I’m sure it will be more interactive when the arguments will be less introductory.

Technorati Tags: , ,

Tags: , ,


Nov 10 2009

My brand new Business Cards

Category: megiordano scalzo @ 2:35 pm

Business Cards
Last week I realized I needed some personal business cards; so I decided to design something different to be printed by Moo.
And yesterday they arrived.

They are very simple: in front, my name, blog and email addresses, the ideogram for “kaizen” (continuous improvement), and a Turkish proverb I like very much “No matter how far you have gone on the wrong road, turn back”; in back a Google-like page with others web places I live.
They lack my telephone number, in part because I own only work telephone and those business cards are about the “other” me, and in part because I feel telephone so ’90s ;-)
What do you think? Do you like the layout?

Technorati Tags:

Tags:


Nov 07 2009

No more excuses 2: junit testing System time

Category: java,tutorialgiordano scalzo @ 2:59 pm

Another common exemple of static dependency, it’s the Time System dependency.
In greenfield project it could be possible inject time into the objects they’ll use it, but in legacy code it’s more difficult, so oftet we gave up and don’t unit test some behaviour dependent from time.

In a recent project, I had the problem to check the correct format of a filename that it had to contain the creation timestamp; I easily overcame it with a nice test pattern made by Paolo “Nusco” Perrotta, well known Ruby Metaprogramming guru, in a version wrote by Bruno Bossola in a nice Open Source project.

In a nutshell, the trick is to adapt System Time with another object.

Let see a simple example.
This is the class to test:

package biz.scalzo.prod;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeFormatter {
	public String now() {
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy/MM/dd HH:mm");
		return sdf.format(new Date(System.currentTimeMillis()));
	}
}

I know it mixes two responsibilities, it has a silly static dependecy and so on, but forgive my oversemplification used to show the pattern.

package biz.scalzo.test;

import junit.framework.Assert;
import org.junit.Test;

public class ATimeFormatter {
	@Test
	public void shouldFormatNowInFancyWay() {
		Assert.assertEquals("2009/10/13 15:29", new TimeFormatter().now());
	}

}

The behaviour to check is how well the Formatter formats current time in string; we have to find a way to set a well know time point so we can check te result of format.

To implement the VirtualClock pattern, we declare a simple Clock interface:

package biz.scalzo.prod;

public interface Clock {
	public long now();
}

and a repository where we can insert our fake clock

package biz.scalzo.prod;

import java.util.Date;

public class SystemTime {
	private static Clock clock;

	private static final Clock defaultClock = new Clock() {
		public long now() {
			return System.currentTimeMillis();
		}
	};

	public static long asMillis() {
		return getClock().now();
	}

	public static Date asDate() {
		return new Date(getClock().now());
	}

	public static void reset() {
		clock = null;
	}

	public static void setClock(Clock aClock) {
		clock = aClock;
	}

	static Clock getClock() {
		return (clock != null ? clock : defaultClock);
	}
}

Now we can change our class using SystemTime instead of System.currentTimeMillis():

package biz.scalzo.prod;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeFormatter {
	public String now() {
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy/MM/dd HH:mm");
		return sdf.format(SystemTime.asDate());
	}
}

In test harness we can inject a fake clock

package biz.scalzo.test;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import biz.scalzo.prod.Clock;
import biz.scalzo.prod.SystemTime;
import biz.scalzo.prod.TimeFormatter;

public class ATimeFormatter {
	private static final long FAKED_TIME = 1255440571354L;

	private void fakeClock() {
		SystemTime.setClock(new Clock() {
			public long now() {
				return FAKED_TIME;
			}
		});
	}

	@Before
	public void setUp(){
		fakeClock();
	}

	@Test
	public void shouldFormatNowInFancyWay() {
		Assert.assertEquals("2009/10/13 15:29", new TimeFormatter().now());
	}

}

and we have green bar! Neat, isn’t it?

I know it’s a lot of code, but in legacy code it’s better than leave a feature without a test.

Technorati Tags: , ,

Tags: , ,


Nov 04 2009

mobile bloging

Category: megiordano scalzo @ 12:26 am

At the end I upgraded my Ipod touch so I can use WordPress for Iphone. It’s quite usable, but of course with a real keyboar the experience is really more powerful.