Friday, November 25, 2005

Object Challenge

Challenges are always something people love to face ..... if you want an example, think to Sudoku success!!!
So, I want to submit you a challenge based on some object oriented crunches.
Give me your attention for some minutes, if you care, or if you don't have something better to do.

Say you have a Car object in your business domain.
It has state and behaviour, so no, it is not an anemic business object.
Say you have, besides all other components, a TransmissionGear which is a part of your car.
It has its good state and behaviour, in particular it has a GearType attribute which defines the actual gear, and a changeGear() method for changing gear.
Car, on its side, has a boost() method which interacts with the TransmissionGear and whose behaviour depends on the GearType.
Take a look at this diagram:

Say the boost() method, depending on the GearType, must do the following:

  • Decreasing Car fuelQuantity and oilQuantity.

  • Calling changeGear() on TransmissionGear

How would you do this?

There's no best method, but surely there's a method better than another one.

If you care, leave a short comment, or simply think.
Think about this.

I'll give you my solution in one of my next posts!

Tuesday, November 22, 2005

Unit testing with the Spring Framework, Part 2

In one of my old posts, Unit testing DAO classes in the Spring Framework, I talked about how to test Hibernate based DAO classes implemented with the HibernateDAOSupport Spring template.

However, inspired by a Matt Raible blog post, I've recently started to use the AbstractTransactionalDataSourceSpringContextTests Spring class.

It's a long time since I want to post about this very interesting piece of thing.

This class provides an easy way to do unit, but I'd better say integration, tests over your Spring managed business objects and services, importing your Spring configuration, loading an appropriate Spring application context based on it, and wrapping your test methods each in a separated transaction which will be rolled back at the end of the method, avoiding so to insert test data into your database tables.

This sounds very good, because you don't have to manually configure Hibernate (it will be configured in your Spring application context), nor to manually manage transactions, nor to worry about unwanted test data!!!

So, you will simply have to:

In your test methods, you can use all normal JUnit assert methods.

Moreover, you will be able to do a lot of other cool things, like accessing a jdbcTemplate variable for making SQL queries, committing transactions instead of rolling them back, or making special setup operations before every test method in the same context of its transaction or in another one.

Take a look at its javadoc.

Good testing!

Tuesday, November 15, 2005

Strange side effects of White Phosphorus (WP)

From an interview to Lieutenant Colonel Steve Boylan, spokesperson for the U.S. military in Iraq, Jeff Englehart, former army Specialist in Iraq, and Maurizio Torrealta, News Editor for the Italian television RAI and co-producer of the film "Fallujah: The Hidden Massacre":

LT. COL. STEVE BOYLAN: We have used it in the past. It is a perfectly legal weapon to use.

AMY GOODMAN: Maurizio Torrealta, news editor for the Italian state broadcaster, RAI 24. Your response?

MAURIZIO TORREALTA: Well, the United States, as the UK and Italy, signed the convention about prohibition of chemical weapons. And the convention define precisely that what make forbidden an agent, a chemical agent, is not the chemical agent itself. Because as Lieutenant said, the white phosphorus can be used to light the scene of a battle. And in that case, it's acceptable. But what make a chemical agent forbidden is the use that is done with it. If you use white phosphorus to kill the people, to burn and to block them, people and animals, even animals say the convention that we all sign, Italy, United States and UK, this is a forbidden chemical agent.

And we are full of picture that show bodies of young people, of children, of women which have strange -- particular, they are dead with a big corruption of the skin and show even the bone. And the clothes are intact, untouched. And that shows there has been an aggressive agent like white phosphorus that has done that. And we have all the number of those bodies and the place where they have been buried. So any international organization that wanted to inquire about that has all the tools and information to do it. And even the witness -- the U.S. military that we interview confirmed that the use of white phosphorus was against the population. And we have even picture of the fact that has been told by the helicopter down to the city, not by the ground up in the air to light the scene. Also the images, they spoke by themselves.

AMY GOODMAN: Jeff Englehart, you are the Specialist -- former U.S. Specialist in the Army, a member now speaking out against the war. You are interviewed in this documentary explaining how white phosphorus was used in Fallujah. Can you tell us more?

JEFF ENGLEHART: Oh, yeah. I mean, I definitely heard it being called for. And I even talked to reconnaissance scouts after the siege, and they said they had actually called for it. The Pentagon spokesperson says that they use this for concealment, or some sources say they use it for illumination. But, I mean, I think that's ridiculous, because we would use -- just based on my training as a reconnaissance scout myself, we would use illumination separately, as it’s on exclusive ground. Since my training, we were taught that white phosphorus is used for troops out in the open or to destroy equipment and that it burns and that the only way to prevent the burning is to douse it with wet mud.

To me, it's definitely a chemical weapon in the fact that it burns, and it burns indiscriminately. In fact, the use of white phosphorus violates the Geneva protocol for the prohibition of use in war of asphyxiating, poisonous or other gases and bacterial methods of warfare. So, I mean, even if the Geneva Protocol says it's illegal, I don't see how we're able to use it and then say that it's used for our own cover or illumination, when it actually could hurt our own troops. So I just think that, from the very top, the big problem with this war is that from the very top to the lowest level soldier, everyone's being lied to. And then the news gets gentrified by the mass media to make it sound like, ‘Oh, well, white phosphorus is a good weapon that we can use to help spot targets,’ when it's actually designed to burn its victims.

How good is White Phosphorus (WP)

From an interview to Lieutenant Colonel Steve Boylan, spokesperson for the U.S. military in Iraq:

AMY GOODMAN: So are you confirming that you used white phosphorus in Fallujah, but saying that it's simply not illegal?

LT. COL. STEVE BOYLAN: White phosphorus has been used. I do not recall it was used as an offensive weapon. White phosphorus is used for marking targets for both air and ground forces. White phosphorus is used to destroy equipment and other types of things. It is used to destroy weapons caches. And it is used to produce a white smoke which can obscure the enemy's vision of what we are doing.

AMY GOODMAN: And you're using it in Iraq?

LT. COL. STEVE BOYLAN: We have used it in the past. It is a perfectly legal weapon to use.

How to survive White Phosphorus (WP) ...

... if you are ACCIDENTALLY hit by WP particles during a military action.

From (see here):

If burning particles of WP strike and stick to the clothing, take off the contaminated clothing quickly before the WP burns through to the skin. Remove quickly all clothing affected by phosphorus to prevent phosphorus burning through to skin. If this is impossible, plunge skin or clothing affected by phosphorus in cold water or moisten strongly to extinguish or prevent fire. Then immediately remove affected clothing and rinse affected skin areas with cold sodium bicarbonate solution or with cold water. Moisten skin and remove visible phosphorus (preferably under water) with squared object (knife-back etc.) or tweezers. Do not touch phosphorus with fingers! Throw removed phosphorus or clothing affected by phosphorus into water or allow to bum in suitable location. Cover phosphorus burns with moist dressing and keep moist to prevent renewed inflammation. It is neccessary to dress white phosphorus-injured patients with saline-soaked dressings to prevent reignition of the phosphorus by contact with the air.

Some nations recommend washing the skin with a 0.5-2.0% copper sulphate solution or a copper sulphate impregnated pad. Wounds may be rinsed with a 0.1%-0.2% copper sulphate solution, if available. Dark coloured deposits may be removed with forceps. Prevent prolonged contact of any copper sulphate preparations with the tissues by prompt, copious flushing with water or saline, as there is a definite danger of copper poisoning. It may be necessary to repeat the first aid measures to completely remove all phosphorus.

White Phosphorus (WP)

From (see here):

WP is a colorless to yellow translucent wax-like substance with a pungent, garlic-like smell. The form used by the military is highly energetic (active) and ignites once it is exposed to oxygen. White phosphorus is a pyrophoric material, that is, it is spontaneously flammable.

White phosphorus results in painful chemical burn injuries. The resultant burn typically appears as a necrotic area with a yellowish color and characteristic garliclike odor.

Incandescent particles of WP may produce extensive burns. Phosphorus burns on the skin are deep and painful; a firm eschar is produced and is surrounded by vesiculation. The burns usually are multiple, deep, and variable in size. The solid in the eye produces severe injury. The particles continue to burn unless deprived of atmospheric oxygen. Contact with these particles can cause local burns. These weapons are particularly nasty because white phosphorus continues to burn until it disappears. If service members are hit by pieces of white phosphorus, it could burn right down to the bone. Burns usually are limited to areas of exposed skin (upper extremities, face). Burns frequently are second and third degree because of the rapid ignition and highly lipophilic properties of white phosphorus.

Friday, November 11, 2005

Your Face Tomorrow

Sometimes I wonder if my life would be a lot better and easier if I didn't know anything.
Anything about people, I mean.
Anything about my friends, my family, even about me, even about unknown people.

This is a strange thing to tell and I don't know if anything of you can understand, but what I think is that people, but I'd rather better say humans, rarely know by itself what they really are and want.
They often build castles and paint pictures of what they would like to be, of what life should be, but this is not reality.
Reality is never clear.

And being unclear in respect of yourself, how can you be clear in respect of other people?

So, I'll never know how your face will look tomorrow, and probably will never know also mine.
I'll never know my friends, my enemies, what is good and what is bad, so the only thing we have to do is trust or don't trust, and left all to time and destiny, which I think, time and destiny, are the same.

This is what people do, this is what people is used to do and want to do, and this is what permit them to stay safe.
Shut your eyes, your mouth, your ears, and be safe.
Because knowing something about you, about people, about life, something that you'd never want to know, really hurts.

I can assure you, waking up some day, discovering that you are not what you think and what you'd like to be, and that people living with you is not what appear to you ... really, really, hurts.

Knowing that your life is somewhat predictable, at least that you could predict what will be good or bad, could kill you, because this would force you to confront life face by face, and would revoke the possibility to say: "I didn't know, I could never have predicted this."

Knowing is responsability.

So, "we love to throw away our shield, marching mild and waving our spear like an ornament".


Inspired by Your Face Tomorrow - Fever and Spear, a novel by Javier Marias.

Tuesday, November 08, 2005

The importance of being extremely built

Ok, as said in my last post, daily builds are good, but what is better?

Like pointed out by my colleague Ugo Cei, like recommended by XP practises, and like well explained here by Martin Fowler, it is better and better to install a Continuous Integration System, in order to go through the "checkout / build / test" process in a fully automated way and many times per day, avoiding the so called "integration hell".

In these days I wanna put my eyes over these open source products for continuous integration:

I'll let you know, so stay tuned.

Friday, November 04, 2005

The importance of being daily built.

Yesterday I was reading "The Joel Test: 12 Steps to Better Code" : I had already read that article, but yesterday I've given it more than a thought.

Among other things, my mind was caught by the third item : "Do you make daily builds?".

My answer was "no", and my question was: why is this so important?
Yes, I said, they are a good thing and let your team check every day if their new commits do not break old builds ... but I didn't give it much importance.

So, at the end of the day, I committed my daily work, closed orwell (for those who don't know, orwell is my linux box), and came back home.

What happened while coming back, was that ... my mind reminded me that I had forgiven to commit also some libraries needed to compile my daily work!!!
And yes, I actually broke the build ... understanding, by experience, how much daily builds are useful.

So, don't be lazy (yes, I know how much hard may be this ...).... and take one or two minutes, at the end of the day, for daily testing your builds!