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.
Saturday, November 20, 2010
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.
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.
Etichette:
outbursts
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...
If you don't know what I'm talking about just take a look at what happened in a world cup semi-final...
Etichette:
rugby
Friday, November 12, 2010
Kinesics differences
Now that's interesting:
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.
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.
Etichette:
kinesics
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:
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.
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 */Note the use of the reserved ${cursor} property that positions the cursor where you are supposed to add your custom code.
public String title(){
TitleBuffer buf = new TitleBuffer();
// TODO add properties
${cursor}
return buf.toString();
}
- 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.
Etichette:
Naked Objects,
NetBeans
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:
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.
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.
Etichette:
database,
design,
domain-driven design,
Dozer
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:
Happy as a clam I wrote another test for the other way round:
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:
Any hints?
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:
@TestI 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.
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());
}
Happy as a clam I wrote another test for the other way round:
@TestStill smiling I hit the CTRL+F6 combination and... WTF? red bar?
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);
}
org.dozer.MappingException: Illegal object type for the method 'setPropTwo'.Hmmm... weird... but not too much after all, I had been too optimistic.
Expected types:
my.package.MyEnum
Actual types:
java.lang.String
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>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.
<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>
Any hints?
Subscribe to:
Posts (Atom)