Tuesday, November 30, 2010

Unlearn your MBA

Be an enterpreneur and invest about one hour of your time to watch David Hansson give a talk at Stanford.



The talk is very interesting, David repeatedly insists on focusing on the importance of delivering value in a profitable way. He's also a good speaker, so time will fly by.

Wednesday, November 24, 2010

Systems Thinking

A bad system will beat a good person every time

W. Eduards Deming

German wisdom

Do like the sundial:
Only count the bright hours

Tuesday, November 23, 2010

7th Italian Agile Day Mind Maps

Too entranced to take notes at the 7th Italian Agile Day, weren't you? don't worry, you can find the mind maps developed during some of the sessions here.

How to create a new object in NetBeans

Another useful java code template is newo, that expands to the following:
Object obj = new Object();
As behind the curtains the expression is

${TYPE default="Object"} ${OBJ newVarName default="obj"} = new ${TYPE}(${cursor});
all you have to do is change the type and note how the IDE at the same time changes the name of the variable setting the first letter in lowercase, e.g. if you hit newo TAB MyObject the result will be
MyObject myObject = new MyObject();
Neat and clean :-)

Saturday, November 20, 2010

7th Italian Agile Day: a review

Yesterday it was held in Genova the 7th edition of the Italian Agile Day, which is so far the best I've ever attended, so the first thing I'd like to do is thank everyone for being there.

As always, I studied the program for about a week before I made up my mind on which sessions I would follow. As always, I didn't follow the plan. Hey, inspect and adapt, right?

After the usual introduction by Marco Abis, who with many others made all this possible, Paolo Perrotta gave the keynote speech, which was very interesting as it revealed a totally unexpected piece of information: software projects have problems, and writing software is difficult. Strange how I never realized that in all these years :-)

Paolo also talked about the waterfall method, which - curiosly enough - was not so "waterfallish" in the intentions of its author; all the problems originated from the (in)famous picture of phases, which originally referred to the phases of a single iteration. Moreover, there was also a clear note that stated that this model could not possibily work. Somehow this detail was lost.

Anyway, great speech, and all my compliments to Paolo that keeps improving his skills as a speaker.

Then I went for "Note to managers: IT is different, get over it" by Andrea Provaglio, which was very interesting and gave me many starting points for further studies. I was a little flustered when, toward the end of the speech, he said that all changes start from the management, which corollary is more or less that you cannot start anything from the ground up. I revived a little when in a private conversation he was so kind to tell me that all you have to do is persuade the management that a change is due. Sounds easy, but it is not. That's why you have to persuade the management that a change is due by showing them why they should be interested in that change, in such a way that they can understand what you're talking about because you use their language, and what would their advantages be. At this point I was quite happy to see that all the time I spend reading Neurolinguistic Programming manuals is not wasted, as Andrea suggested just what all the manuals do... there must be a reason if everybody agrees on that!

I didn't change the room for next talk by Fabio Armani, "Scrumban, a methodology fusion". Unluckily what should have been a nice background music became too loud to be kept so he had to turn it off. Another annoyance was the projector (or maybe the computer) that kept running out of sync. Putting aside technical problems - wich are always lurking when you have a public, no matter how many times everything went right just before the showtime - Fabio explained how he trains his teams and how they perform. Man, I want to work like that!

In the afternoon, after a very long queue for lunch, the first session was "The secret art of Agile Javascripting" by Luca Grulla. I think that if I had to manage a project with more 50% of the codebase written in Javascript I could just as well get mad. I mean, madder than I already am, of course. But, again, that is because I don't know the language as well as I'd like to (and, alas, as well as I should). Anyway, I'll try to follow his advice: separate what must be separated. And, yes, the DOM is an integration point as well.

Next, I ran to follow Alberto Brandolini for "Due uomini e una lavagna", which was absolutely different from what I was expecting, yet it was another great presentation, from which you could get all his passion and sound expertise. This was the occasion to meet him in the flesh after we exchanged a bunch of posts and comments: I knew he was a prolific writer, but I didn't know he had such a high count of words per second :-)

I was quite undecided for the last session (just like for the others), then I went for "TDD per le viste", a "pomodoroed" session by Matteo Vaccari and Carlo Bottiglieri. I already knew what to expect by Matteo, having seen a slightly modified version of his slides, but Carlo's part of the presentation was quite shocking. The reason of this lies in his (paraphrased) sentence "I was not told that TDD was just for the domain, so I started applying it for everything. TDD is a support for taking informed decisions, and it must be used as such". Sounds extreme, but probably it is not, we only have to get used to it.

And, just like that... it's gone!

The conference was really rich in contents, fast paced, and very well organized. Soon the recordings of all the sessions should be available online here. Also the funding went very well, with more than €5.500 donated by the community for the community (and while donating I also I brought home a wonderful shirt with a "will refactor for food" writing!).

What else... looking forward to the 2011 edition!

Another rainy day for Italy

Today Italy lost 32-14 to Australia in a not very exciting match, despite both team showed something interesting. It is quite surprising how Italy was not able to turn their scrum superiority into more points, and it is also a pity that Rockt Elsom was allowed to "steal" a try in the last action of the match - and with stealing I mean that he was ready and able while Italians were a little sleepy, not that it was not a legal try, I'll leave those rants to "soccer experts", thank you very much.

And, talking about soccer, let me point out that hell will freeze over before you can spot an Italian soccer player sing our national anthem, while in rugby matches not only all players sing it, just like the crowd, but all the children join them too.

Tuesday, November 16, 2010

Ignorance strikes back

I know that sometimes I can be hard to put up with. Actually, "almost always" probably pictures it better. But I really can't help it, even if I know I'm fighting a losing battle. Sometimes it feels like getting blood out of a stone.

Now, to quote Wikipedia, SCSI is a set of standards for physically connecting and transferring data between computers and peripheral devices. Wikipedia also specifies that it sounds like "scuzzy". But that's only phonetical, as you always write "SCSI". Or do you?


Forgive me for the bad quality of the picture, but this is more or less a stolen image; anyway, to protect the (not so) innocent, no references to the place where it has been taken will be given.

Let's just say that the person in charge for materials also systematically writes badget instead of budget, IP adress instead of address, and that's not all folks.

Am I being mean? Probably I am. But I must admit I can hardly put up with wannabe high horses when they don't walk the walk. Let's face it, I am obviously not omniscient and make many errors as well: actually that's the only way you can learn. But if you want to improve you have to work hard, and I do. As I read somewhere, you might not get all you work for, but you will not get what you don't work for.

If you ever see me doing something like that please correct me; I'll also be happy to be exposed to laughter if that can help me to learn something.

Saturday, November 13, 2010

Argentina defeats Italy

Maybe after today's match someone will spot the difference between a wannabe, although good, and the real thing.

If you don't know what I'm talking about just take a look at what happened in a world cup semi-final...

Friday, November 12, 2010

Kinesics differences

Now that's interesting:

The observation of bilingual speakers indicate that these [behaviors and signals] are semi-independent systems which must be examined in context. The significant aspect of this is that as a bilingual speaker changes languages he also changes kinesic systems.

I'll try to pay more attention to see whether I can spot this. Actually it should come as no surprise, as we've seen a thousand times that when you're trying to express yourself in a language you don't master your gestures utterly increase.

Naked Objects Templates in NetBeans

Within the Naked Objects distribution you can find some Eclipse code templates that can speed up your work. Of course also in NetBeans you can have code templates, but I didn't know (and still don't) how to transform the lowercase property in a camel-case get or set method. After envying the Eclipse users for a while I decided to give it a try myself. I was quite deluded, as neither the Eclipse templates allow you to do it. This pushed me to implement the templates myself, and obviously to share my results.

The very first template is probably nop, which stands for Naked Objects Property. This basically creates a property with its setter and (annotated with @MemberOrder) getter. The problem is that I like to keep fields separated from setters and getters, so a template was not the best solution (at least not for me). The nop templates was then replaced with the ready-made ALT+INS, Add Property...


This opens a form that lets you specify the property name, type, and tweak the rest of the generated code a little bit.

And so much for the first template, as all I still need to do is to manually add the @MemberOrder annotation on the getter (but the autocompletion feature is of great help, as a simple @Mem followed by CTRL+space is normally enough).

To create a new code template you have to click on the Tools menu, select the Options item, and when the form opens click on the Code templates tab:


A click on the New button, some clickety clackety and a click on the OK button and there you have it: a brand new template all for you. The templates I've created so far:
  • noft (Naked Objects Factory Transient)
/** Creates a new transient ${Type} */
public ${Type} new${Type}(){
${Type} ${instance} = newTransientInstance(${Type}.class);
return ${instance};
}
  • noidicon (Naked Objects Identification Icon)
/** The name of the icon that represents the object */
public String iconName(){
return "${iconName}";
}
  • noidtitle (Naked Objects Identification Title)
/** A description of the object */
public String title(){
TitleBuffer buf = new TitleBuffer();
// TODO add properties
${cursor}
return buf.toString();
}
Note the use of the reserved ${cursor} property that positions the cursor where you are supposed to add your custom code.
  • nopval (Naked Objects Property Validation)
/** Validation for property ${property} */
public String validate${Property}(${Type} ${value}){
if ((${value} == null)) {
return null;
}
// TODO implement imperative rule
${cursor}
return null;
}
Last but not least
  • nopval (Naked Objects Property Validation)
/** Find all ${TypePlural} */
@Exploration
public List<${Type}> findAll${TypePlural}(){
return allInstances(${Type}.class);
}

I'm sure I can do better than this, e.g. there should be a way to automatically fix imports without the need for me to hit SHIFT+CTRL+I - which, anyway, is not all that work, moreover I'm more than used to combine it with ALT+SHIFT+F to format code and CTRL+S to save whenever I type something.

As with all code templates, use the Tab key to switch from a variable to the next one and hit Enter when you're done.

Maybe more on this will follow.

Wednesday, November 10, 2010

Is Open Session in View an AntiPattern?

A friend of mine pointed me to a willingly provocative article that describes Open Session in View as an AntiPattern. After sharing some thoughts with him, I've decided to post them here.

I agree on the N +1 queries problem, but unless (and until) you have devastating impacts on performances I would not worry about it, applying a YAGNI approach. On the other hand, if a view requires a lot of fetches maybe DTOs come in useful (and I would suggest Dozer). This also semplifies the objects exposed, thus hiding from the "high" layers of the application all the complexities that exist within the domain.

Personally, one of the reasons for which I found Struts 1 frustrating - yet much better than the proprietary framework we were using at the time - was the need for form beans, which lead to tons of duplications (no Dozer yet, a long time ago in a galaxy far far away we only had some Commons Beanutils) which is normally bad. OK, forget the "normally" part.

As a general rule I think that exposing domain objects can be accepted if and only if they are true domain objects, not beans with a bunch of setters and getters and transaction scripts in disguise, otherwise you could bypass many of the application logics and end up with an unmanageable mess.

And, talking about layers leaking, I would also like to quote a couple of sentences from the Domain-Driven Design Using Naked Objects book which I suggest as a very interesting and useful reading:

It takes real skill to ensure the correct separation of concerns between these layers, if indeed you can get an agreement to what these concerns really are. Even with the best intentions, it's all too easy for custom-written layers to blur the boundaries and put (for example) validation in the user interface layer when it should belong to the domain layer. At the other extreme, it's quite possible for custom layers to distort or completely subvert the underlying domain model.


The leaking of the persistence layer is not good per se, but if it does not become a problem you can live with it. As always, it depends on circumstances: why should a spend an incredible amount of resources (which means time and money) to obtain perfect isolation if I don't need it?

In general I think Open Session in View to be a good solution to manage database connections, but it would be even better leverage this strategy with join fetch queries for the most important relations. After all, when writing a service or a facade we know what objects will be needed: this does not mean that the domain or the controller should depend on the presentation layer (they must not!), but pretend that we don't know anything about it is just a waste of time. So, for example, if our facade has a result factory this could be a nice place to eagerly load all objects we know the presentation layer will need; if the view still needs more objects the open session can provide them on the fly: in this way we can optimize the most important parts and live with the rest.

Wednesday, November 3, 2010

Dozer and enums

While trying to map a persistent heavyweight class to a cleaner (and much smaller) POJO I also wanted to substitute some String parameters of the persistent class to Enums. The tool of choice is Dozer, of which I already wrote.

As I had the possibility to create the POJO from scratch I choose only the properties I needed and used the same names of the persistent class, thus having no need to write a custom mapping at all.

To check that everything was working fine I wrote a unit test - what else would you expect? :-) - as simple as that:
@Test
public void testPojoToPersistenceEntity() {
System.out.println("testPojoToPersistenceEntity");
MyPojo pojo = new MyPojo(
propOne,
propTwo,
propThree,
propFour);
MyPersistentClass persistent = mapper.map(pojo, MyPersistentClass.class);
assertNotNull(persistent);
assertEquals(propOne, persistent.getPropOne());
assertEquals(propTwoTxt, persistent.getPropTwo());
assertEquals(propThreeTxt, persistent.getPropThree());
assertEquals(propFour, persistent.getPropFour());
}
I run the test and got a green bar for free. You may notice that in the comparison there are a couple of different variables: these are the names of the Enums, and I was quite pleased with the fact that Dozer had silently mapped them just as I expected.

Happy as a clam I wrote another test for the other way round:
@Test
public void testPersistenceEntityToExistingPojo() {
System.out.println("testPersistenceEntityToExistingPojo");
MyPersistentClass persistent = new MyPersistentClass(
propOne,
propTwoTxt,
propThreeTxt,
propFour);
persistent.setPropFive(propFive);
persistent.setPropSix(propSix);
MyPojo pojo = new MyPojo(
propOne,
propTwo,
propThree,
propFour);
assertEquals(0d, pojo.getPropFive(), 0.01d);
assertEquals(0d, pojo.getPropSix(), 0.01d);
mapper.map(persistent, pojo);
assertEquals(propFive, pojo.getPropFive(), 0.01d);
assertEquals(propSix, pojo.getPropSix(), 0.01d);
}
Still smiling I hit the CTRL+F6 combination and... WTF? red bar?
org.dozer.MappingException: Illegal object type for the method 'setPropTwo'.
Expected types:
my.package.MyEnum
Actual types:
java.lang.String
Hmmm... weird... but not too much after all, I had been too optimistic.

After a little investigation, and taken for granted that I didn't want to write a custom mapper for each and every enumeration I could need, given the current conditions of use of the POJO I tried to map a one-way relationship. The problem is that when you mark a field as one-way Dozer only maps from <class-a> to <class-b>, while I needed exactly the opposite behaviour. Changing the order of the classes was not an option as we use the convention of mapping all the domain classes as <class-a> so I had to revert to the <field-exclude> syntax:
<mapping>
<class-a>my.model.package.MyPersistentClass</class-a>
<class-b>my.package.MyPojo</class-b>
<field-exclude type="one-way">
<a>propTwo</a>
<b>propTwo</b>
</field-exclude>
<field-exclude type="one-way">
<a>propThree</a>
<b>propThree</b>
</field-exclude>
</mapping>
Not exactly what I had in mind, because it doesn't let me create a new instance of a POJO, but for now it will suffice.

Any hints?

IAD 2010 sold out

I hope you registered as soon as you could, because for the umpteenth year (and running) the Italian Agile Day is sold out. Hope to see you there!

Tuesday, November 2, 2010

The power of e-mails

Have you ever noticed how your phone calls that normally fall in the virtual recycle bin are immediately answered when sent in an e-mail of which your bosses receive a courtesy copy?

In a slightly more edulcorate version you could limit the cc to your own boss only, but if she doesn't take the appropriate actions this seems to fail as well. On the contrary, it looks like people don't like their bosses to think they're not doing a good job, thus spreading the impression that their whole department is not doing a good job, leading to the need for them to take action (should a good boss be a good "politician" as well? that's the argument for another post).

I personally don't like this kind of stuff, because I think one should not work just to keep the fan far away from the soup (to be polite) but to create value, both for himself and for the company he's working for.

Sad but true, when you're back to reality and all else fails...