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...
Saturday, November 13, 2010
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?
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!
Etichette:
agile
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...
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...
Etichette:
people
Subscribe to:
Posts (Atom)