Eric Evans is the author of Domain Driven Design, a text which explains the importance of having a software closely related to the real domain it models; the book presents best practices, principles and techniques based on real experience.
I found it challenging but very interesting, but one friend of mine found it thick as a brick. Luckily for M. (and I'm sure for many other people out there) InfoQ has released Domain Driven Design Quickly, which does not introduce new concepts but summarizes the essence of what DDD is, drawing mostly on Evans' book as well as other sources.
You can download a free online version, but you are invited to support the work and buy a print copy.
Thursday, February 28, 2008
Monday, February 25, 2008
The Empire Strikes Back
Ok I know England is not an empire any more, but the temptation was too big. England defeated France at the Stade de France for the second time in a row, in front of an astonished public. After a very enjoyable and quite balanced match Yachvili brought the score at 13-19, leaving France only six points behind with about five minutes to score a try and possibly win the match. At this point the English scrum, only a few inches from the French goal line, did a terrific job keeping possession of the ball for three endless minutes and threatening to kill the match. The final and deserved try by Wigglesworth fixed the score at 13-24. Brian Ashton declared himself "pretty pleased".At Croke Park the home team overpowered Scotland 34-13. The Scots will likely contend for the unwanted Wooden Spoon with Italy.
We wish all the best to the Englishman James Haskell (nothing to do with the programming language) and the Scot Jim Hamilton who both suffered an ankle injury.
Etichette:
rugby,
Six Nations 2008,
wooden spoon
If we say it won’t be closed, then it won’t be closed.
These are the words Mallet said after rain was forecast for the clash between Wales and Italy; they regard the possibility to close the roof of the beautiful Millenium Stadium in Cardiff (even if the Arms Park had a whole different charm which I really loved). Mallet believes (and I do believe) rugby should be a game for all weathers, and that players should adapt to any type of condition. Maybe he also believes he has a pack stronger than the backs, and a muddy field would help their game, as the Welsh backs are far stronger than the Italians.
Well, the roof was not closed. Neither the Italian defense was, but it rained tries and points and the Welsh simply run over us, turning the half time 13-8 into an embarassing 47-8: 34 unanswered points. At least we scored a try, but there were too many careless errors. And this Wales is hungry. A nice debut in the Six Nations for young Andrea Marcato who played a good match.
Now Wales is heading for the Triple Crown and for the Grand Slam, with Ireland and France on the way. Are the Seventies back?
Well, the roof was not closed. Neither the Italian defense was, but it rained tries and points and the Welsh simply run over us, turning the half time 13-8 into an embarassing 47-8: 34 unanswered points. At least we scored a try, but there were too many careless errors. And this Wales is hungry. A nice debut in the Six Nations for young Andrea Marcato who played a good match.
Now Wales is heading for the Triple Crown and for the Grand Slam, with Ireland and France on the way. Are the Seventies back?
Etichette:
Grand Slam,
rugby,
Six Nations 2008
Friday, February 22, 2008
Severance pay part II
Right, you spotted me. I closed last post with a joke. No, no, the scalping part was ok, I was talking about the estimates. You do have to estimate. And we did. And we went to talk to the management, reporting that the new feature would only require about a couple of days. If the code were reasonably clean and understandable, which is not. At this point we tried to explain why we need to spend five days writing tests and refactoring (actually ten days, as two team members are pairing on it).
The discussion went on like this (M = Manager, T = team):
M: How can we ask our customer to pay twelve days...
T: ...er... fourteen, we already spent a couple of days trying to figure out...
M: Exactly! how can we bill fourteen days for a feature that would normally require two?
T: That's right... but if you want to bill two days, nobody will ever pay us for the remaining twelve...
M: Well... the domain logic is very complicated, we could ask for five days...
T: Yes, but we would still need a couple of days whenever the customer asks to fix or add something just to reckon what's going on under the hood, and we can't always say we need more than we actually do... that would lead us to an unhappy customer... and...
M: OK we'll talk about it next week... I want to understand.
Now, what's the point? he is right. But we are right as well. And the customer too. How will our heroes sort that out? More on this will follow...
The discussion went on like this (M = Manager, T = team):
M: How can we ask our customer to pay twelve days...
T: ...er... fourteen, we already spent a couple of days trying to figure out...
M: Exactly! how can we bill fourteen days for a feature that would normally require two?
T: That's right... but if you want to bill two days, nobody will ever pay us for the remaining twelve...
M: Well... the domain logic is very complicated, we could ask for five days...
T: Yes, but we would still need a couple of days whenever the customer asks to fix or add something just to reckon what's going on under the hood, and we can't always say we need more than we actually do... that would lead us to an unhappy customer... and...
M: OK we'll talk about it next week... I want to understand.
Now, what's the point? he is right. But we are right as well. And the customer too. How will our heroes sort that out? More on this will follow...
Etichette:
legacy
Thursday, February 21, 2008
Severance pay
We need to add a new feature to a severance pay software. Legacy software. Very legacy. Normally we would discuss the requirements, inspect the code, estimate, sign an agreement, develop, release and get the money. We do not even need more than one iteration, as the change is relatively simple and small. All is well until we reach the "inspect the code" part (yes, just the second step...).
The code is a nightmare in which side effects rule the world, and you're not even aware of it. As time goes by, and your understanding of the code increases ("understanding" is a real overstatement) you start to realize that democratically elected objects and methods are no longer in power: the dark times of side effects have come, good code long time forgotten. And you are doomed to become insane. Of course, being already on my way to insaneness, I have an undeserved advantage. But that's a whole different story.
Well, we definitely have to understand this code. After banging our heads on the wall for some time we decide that the first thing we'll do is to look for the side effects and turn them into methods which names tell you the story, so if a method sets the foo variable it is called setFoo and not getTheValueOfThatFieldCalculatedForThatPeriod. Easier said than done, because side effects have side effects, which in turn have side effects and so on. The FIRST thing we have to do is to build a test harness (don't tell me you thought for a single moment the code had tests). Thus, as everything that happens deep in the dungeons of the code is a strange mixture of lore, smoke and magic - and an insane amount of luck - we decide to test the final output of the whole calculation. Ok let's do it.
First: let's create some test data, decoupled from the database. After all, we don't want to waste unnecessary time hitting the database (and we should all refer to the same one). That's long but easy, as many values and properties are required. while (not done) {Clicketi clacketi tic tic clack click clack} ok we're done. Let's write a simple test and let's check the very last value that the output page would display. Clack click clack... Run test...
...Error: xxx.persistence.XxxPersistenceException: pkg1.pkg2.pkg3.CoefficientTable: no default connection found.
NO DEFAULT CONNECTION FOUND? Whatthe... ok, ok, the application reads the coefficients used in the calculations from a database. We make a note to decouple it later, maybe the application will load them during the startup, we do not care where they come from, what we really want is to inject the coefficient data when we actually need to make the calculations. For now let's use a TestSetup and connect to the database (and disconnect when we're done). Running JUnit tests...
1 test failed... junit.framework.ComparisonFailure
ComparisonFailure? But if I actually print the page I get the right result... and the property I check in the test is the one we use for the output... What...???
A-ha! That's where we discover that the software that calculates the final values does not really calculates the final values, despite the name of the methods, because the class that generates the HTML of the output page (why a class? why not a servlet? why not a simple jsp page and a bean?) makes even more calculations. Yep, you guessed, based on side effects as well. Undeclared and inconceivable side effects, of course.
I do not dare to ask my team to estimate the tasks for the new feature... I do not even dare to ask them to estimate the time they will need to be able to estimate the new feature...
Let's close our eyes, hold our noses and refuse to listen... any free wall? we've got some heads to bang... BUT NOT OURS! My team members want the scalp of the original developers... and who am I to prevent them to be happy?
The code is a nightmare in which side effects rule the world, and you're not even aware of it. As time goes by, and your understanding of the code increases ("understanding" is a real overstatement) you start to realize that democratically elected objects and methods are no longer in power: the dark times of side effects have come, good code long time forgotten. And you are doomed to become insane. Of course, being already on my way to insaneness, I have an undeserved advantage. But that's a whole different story.
Well, we definitely have to understand this code. After banging our heads on the wall for some time we decide that the first thing we'll do is to look for the side effects and turn them into methods which names tell you the story, so if a method sets the foo variable it is called setFoo and not getTheValueOfThatFieldCalculatedForThatPeriod. Easier said than done, because side effects have side effects, which in turn have side effects and so on. The FIRST thing we have to do is to build a test harness (don't tell me you thought for a single moment the code had tests). Thus, as everything that happens deep in the dungeons of the code is a strange mixture of lore, smoke and magic - and an insane amount of luck - we decide to test the final output of the whole calculation. Ok let's do it.
First: let's create some test data, decoupled from the database. After all, we don't want to waste unnecessary time hitting the database (and we should all refer to the same one). That's long but easy, as many values and properties are required. while (not done) {Clicketi clacketi tic tic clack click clack} ok we're done. Let's write a simple test and let's check the very last value that the output page would display. Clack click clack... Run test...
...Error: xxx.persistence.XxxPersistenceException: pkg1.pkg2.pkg3.CoefficientTable: no default connection found.
NO DEFAULT CONNECTION FOUND? Whatthe... ok, ok, the application reads the coefficients used in the calculations from a database. We make a note to decouple it later, maybe the application will load them during the startup, we do not care where they come from, what we really want is to inject the coefficient data when we actually need to make the calculations. For now let's use a TestSetup and connect to the database (and disconnect when we're done). Running JUnit tests...
1 test failed... junit.framework.ComparisonFailure
ComparisonFailure? But if I actually print the page I get the right result... and the property I check in the test is the one we use for the output... What...???
A-ha! That's where we discover that the software that calculates the final values does not really calculates the final values, despite the name of the methods, because the class that generates the HTML of the output page (why a class? why not a servlet? why not a simple jsp page and a bean?) makes even more calculations. Yep, you guessed, based on side effects as well. Undeclared and inconceivable side effects, of course.
I do not dare to ask my team to estimate the tasks for the new feature... I do not even dare to ask them to estimate the time they will need to be able to estimate the new feature...
Let's close our eyes, hold our noses and refuse to listen... any free wall? we've got some heads to bang... BUT NOT OURS! My team members want the scalp of the original developers... and who am I to prevent them to be happy?
Scholfield Huxley
On with the Spoon River Anthology... today's verses are quoted from Scholfield Huxley:
How would you like to create a sun
And the next day have the worms
Slipping in and out between your fingers?
Fills you with cheerfulness, doesn't it?
How would you like to create a sun
And the next day have the worms
Slipping in and out between your fingers?
Fills you with cheerfulness, doesn't it?
Etichette:
poetry
Tuesday, February 19, 2008
Hallway usability testing, TDD and pair programming
The hallway usability testing is one of the twelve steps to better code proposed by Joel Spolsky; it goes
"A hallway usability test is where you grab the next person that passes by in the hallway and force them to try to use the code you just wrote. If you do this to five people, you will learn 95% of what there is to learn about usability problems in your code."
I never heard of such a simple yet smart trick before. Maybe because the hallway usability testing is a close relative of the combination of different XP (and not only XP) practices such as Test Driven Development, in which tests are the first users of your classes, pair programming with frequent pair rotating, in which you don't need to stalk the hallway to get somebody's attention, and collective code ownership, which causes everyone to shower insults at you (in a friendly manner, of course) when you deserve it.
That is another demonstration, should it be needed, that there are different effective paths leading to the same goal.
"A hallway usability test is where you grab the next person that passes by in the hallway and force them to try to use the code you just wrote. If you do this to five people, you will learn 95% of what there is to learn about usability problems in your code."
I never heard of such a simple yet smart trick before. Maybe because the hallway usability testing is a close relative of the combination of different XP (and not only XP) practices such as Test Driven Development, in which tests are the first users of your classes, pair programming with frequent pair rotating, in which you don't need to stalk the hallway to get somebody's attention, and collective code ownership, which causes everyone to shower insults at you (in a friendly manner, of course) when you deserve it.
That is another demonstration, should it be needed, that there are different effective paths leading to the same goal.
Etichette:
pair programming,
testing
Subscribe to:
Posts (Atom)