Tuesday, June 30, 2009

Goodbye Pedro

After winning four Italian titles, after playing with the Italian National Team, after many satisfactions Pierpaolo Pedroni has been - way too early - summoned to play in the selection of rugby legends in the most beautiful stadium over the rainbow.

When my friend Pancho gave me the news I couln't believe him, as I had just met Pierpaolo, who was only 45 years old, less than a month ago in Cernusco, where he won the Vets cup with the Alcolizzati.

Somebody says that rugby players never die, at the most they hand the ball. Goodbye Pedro, we'll meet at the fourth half.

Friday, June 26, 2009

NetBeans and Frameworks

NetBeans seamlessly provides an integration with the most common frameworks, e.g. GWT, jMaki, Spring Web MVC, JSF, Struts, Hibernate.

When we create a new project we are asked whether we want to use any of these frameworks in our application. Should we need to add them later it is very easy to do so: from the project properties you select the Frameworks category, click the Add... button, select the framework(s) you need and you're done, as NetBeans takes care of (almost) everything, e.g. if you add the Hibernate framework NetBeans will add the necessary libraries and references and create a hibernate.cfg.xml file.

What I never managed to realize is how you get rid of a framework, as there are no Remove buttons whatsoever. That's where a versioning system comes useful (disclaimer: this is definitely NOT the only reason for which you should use one). If you have your whole project under versioning (including NetBeans administrative files) as we do, after committing everything on the repository you can simply add your framework and ask your versioning system to show you the changes and use a simple diff on each modified or added file and save the differences for future reference: in this way you can pretend you know the NetBeans internals like the back of your hands, while you just used a sleight of hand.

If you want to remove the framework now you can just revert all modifications and delete added files, but if you want to remove it after some other coding you can always go back to your reference files.

I'm sure there's a way to automate all this at least a little bit, but for now I'll be content with this.

Tuesday, June 23, 2009

Testing an interface in JUnit4

How do you test an interface? Obviously, there is no way to instantiate it directly, so you have to write a test for each different implementation. I feel shivers down my spine even as I write it... that awfully smells like duplication, which - should you ask - is bad. Nevertheless, I'd like to test every possible implementation.

As JUnit Recipes reports, this is quite simple:
  1. Start from the test case for one of the implementation (I assume you have them, don't you?)
  2. Create a new abstract test case in which you will define the expected behavior
  3. Have your test case extend the abstract test case
  4. Move the code that instantiates the object under test into a separate method, storing the object as a reference to the interface and not the implementation.
  5. Adjust the rest of the code referring to the interface behavior accordingly
  6. Create an abstract creation method for each concrete creation method
  7. Move all tests for the interface to the abstract test case
At this point in the test cases for the implementations there should be only implementation specific behavior, not related to the interface.

I tried it all in JUnit 4... and it didn't work, as when I ran the tests for all the project I got a wonderful java.lang.InstantiationException (actually several of them) for the abstract test case.

After some personal tries and a bit of googling I found that all I needed to do to have everything run smoothly was to add the @Ignore assertion to the abstract test case. Now we have no excuses!

Monday, June 22, 2009

Don't comment bad code

Don't comment bad code - rewrite it.

The quote belongs to Brian W. Kernigham and P.J. Plaugher (and I'm sure to many others). It might sound simple... yet I perceive it as so powerful! It puts your back to the wall with the choice to devote yourself to leave your campfire slightly better than you found it... or to simply turn your head.

Uncle Bob has a similar opinion on the subject:

"Ooh, I'd better comment that!" No! You'd better clean it!

Commenting bad code derives from the fear to actually modify it. But beware:

Fear is the path to the Dark Side.

Get rid of modifiers

When you are performing queries you sometimes want to treat modified letters like their corresponding unmodified ones, e.g. è should be treated just like a plain e.

The first algorithm that comes into your mind is probably a long switch of modified characters, which is horribly ugly. The second one could be a map, slightly better but still ugly. Both approaches require quite an amount of work, and I didn't (I still don't) like them.

After investigating a little and asking some friends I was more or less resigned, until Gabriele pointed me to what I was actually looking for: the java.text.Normalizer, that lets you transform an ugly string into a neat one with just a single line of code:

result = Normalizer.normalize(myString, Normalizer.Form.NFD);
return result.replaceAll("\\W", "").toUpperCase();

Now, that's what I call quite good...

What do Scrum and Nintendo Wii have in common?

Find it out here.

Wednesday, June 17, 2009

What's in a programmer's head

I would like to say "humility", as there should be in other professionals. Instead, what I most experience is hubris, which can be good - but it can also hinder you.

That's why we should always listen to people who criticizes us, especially if they know us well (and if I may add, when they stop firing at us it'll mean they don't care anymore, and that would be very bad). To quote Senator Amidala:

Our mentors have a way of seeing more of our faults than we would like... it is the only way we can grow.

I am reading several resumes, and I often find sentences like "five years experience in (you name it)". What I would like to know in advance is if that means "I've constantly grown in the last five years" or "I've repeated the same six months experience ten times". I'll let you reckon which is the most frequent case.

Embrace Change

Not only the subtitle for Extreme Programming Explained. Changes happen, that's the only thing you can be sure of. Things change, people change, hair styles change (actually I'm quoting here). So we must be open to change.

I've seen POs swap projects, new projects created, weeks of planned work cut, people added to workforce, people cut from workforce, and much, much more in less that a fortnight. Is that bad? it is, if you're lost with no hints. On the other hand, it is also an opportunity.

If you spent some time in serious planning you have a good basis on which you can build your ability to steer the change. That does not mean that you need a good plan (which could now be completely worthless), but that you have a solid knowledge of what's on the table, and that means more information, which translates into a conscious decision instead of a jump in the void (or at least it mitigates the risks).

And let me say that again:

The waterfall model is wrong!

Milano Rugby Festival 2009 Pictures

On the official site of the event you can find a bunch of pictures of the 2009 edition of MRF; I'll just post this appetizer... or is it?


See you next year!

Friday, June 12, 2009

Estimating or Guesstimating?

Everybody would like to know in advance all informations, risks and variables when they need to estimate something. The purpose of estimating is manifold, so we always have to give our best because a wrong estimate might reflect on many things.

What we always have to remember is that we seldom can estimate on a completely solid ground. That's why we normally introduce a corrective factor, which is absurdly big at the start of a project and narrows while the latter proceeds.

Sometimes you lack important pieces of information, nevertheless you have to guesstimate. It should be clear to everybody (at least it is crystal clear to me) that if you guesstimate an effort of 100 it could actually be a value between 60 or 160 (PMI says between 75 and 175, which is a more pessimistic but probably better correction). Guesstimates are not contracts, and they cannot (they shouldn't) be used against you. Thus, we must not be afraid of guesstimating; it often helps us to clarify some aspects of what's ahead of us.

"I don't have enough information" is a very good justification, and it must be respected, but it cannot be an excuse. I know it can be subtle, but that's how I see it. After all, as an old keyring of mine reported...

right or wrong, I'm still the captain

Tuesday, June 9, 2009

Alcolizzati rule

Alcolizzati are back... just as we all remembered them: as winners. This time they beat 26-7 the Heath RFC from England to win the Vets 10s Cup in the Milan Rugby Festival held in Cernusco last weekend.

The Ingolstaadt Baboons (GER) lost the Bowl Final to the NRDC Rugby (ITA), just as the Mucche Pazze (ITA) lost the Shield Final 0-22 to the London Nomads (ENG). Butleigh (ENG) won the Plate Final defeating for 17-0 the Ragazzi Sani (ITA).

Winners of the Cup Final are the Sabbie Mobili (ITA) who defeated Benfica (POR).

But the most important prize of the event was, once more, awarded to the Ingolstaadt Baboons, who obviously decided to specialize in that very difficult competition which is the Cassie Pienaar Trophy.

Monday, June 8, 2009

Thanks to all Chickens

El Dì del Ghezz was a truly wonderful event, featuring Chickens from the 40s (some tottering, some still showing their skills, every single one as happy as a child) to the younglings, all with the green and yellow shirt. It was a great occasion to meet many friends I'd lost contact with, either teammates or opponents.

I bet "el Ghezz" spent all day smiling down at us.

Just for the record, the Chickens of the 70s beat the Chickens of the 80s 4 tries to 2 (goal kicks don't count in these occasions), showing that the heart still counts more than age ;-) even if I should say we drew, in perfect Chickens style.

I just played for a few minutes, but they were more than enough to awaken the beast in me: I just can't get enough... and I'm longing for more. Who knows. Up to now, I just can say that my first and last day with a rugger have been in green and yellow, so thanks again to all Chickens.

Friday, June 5, 2009

I'm still ill (and I don't want to be healed)

Rugby is the most extraordinary disease in the world, and a couple of days ago, thanks to my friend Gigi, I found out (should I need more evidence) I'm still infected.

Tired but happy, I completed almost one hour of touch rugby with many enthusiastic players, some of which really gifted (you can spot them quite easily, even from the smallest gestures). I want to personally thank each of them for the warmest welcome and for the great support. I'm looking forward to meeting them again at the Milano Rugby Festival which will be hold in Cernusco this weekend.

It was great, and it was like these ten years had never passed. Well, they actually have, as I couldn't do all I used to, or all I'd have liked to, but that does not matter. I was there. And I played. I also got a couple of bruises!

The evening went on even better, dining at La Ciotola di Jarop with other rugby players (some of them former rugby players, which, as I already explained, to me means "people who used to play rugby, don't play anymore, but still have rugby in their heart"), owned by Pierpaolo, another team-mate of them. Highly recommended!

And tomorrow will be another great day... el dì del Ghezz!

Tuesday, June 2, 2009

The gum shield is ready

Even if I must admit I have lost a bit of my touch, as moulding it took me far more than it used to. But the real question is... will I be ready? My friend Pancho wittily asked me if my opponents would be, and I answered him that they were already more than ready about ten years ago. We shall see. All I can say now is that I'm really looking forward to this special celebration.

Hope to see you there

ps tomorrow I'll have a small appetizer, playing touch in Rome