Extreme Programming Installed
Extreme Programming Installed
7
Chapter 1 Extreme Programming . . . . . . . . . . . . . . . . 9
Extreme Programming is a discipline of software development with values of simplicity, communication, feedback
and courage. We focus on the roles of customer, manager,
and programer and accord key rights and responsibilities to
those in those roles.
Forward . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Chapter 2 Circle of Life . . . . . . . . . . . . . . . . . . . . . . 27
An XP project succeeds when the customers select business
value to be implemented, based on the teams measured
ability to deliver functionality over time.
On an Extreme Programming team, two programmers sitting together at the same machine write all production
code.
stick together, and break the story down into small parts.
Youll be surprised what you can do.
Preface
How much would you pay for a software development team that would do
what you want? Wait, dont answer yet what if they could also tell you
how much it would cost, so that you could decide what to do and what to
defer, on your way to your deadline? You also get quality software, a
robust array of tests that support the project through its entire lifecycle,
and an up to date, clear view of project status. Best of all, you get the ability to change your mind about what you want, at any time.
There arent any silver bullets in software development, and there
probably never will be. However, Extreme Programming is a simple set
of common-sense practices that, when used together, really can give
you most of what you just read in the paragraph above. In this book,
we tell you what the XP practices are, and how to install them in your
project.
If you are a software developer, a programming manager, or an individual who needs software written, this book will be of use to you.
Everyone with a stake in the success of a software development effort
has the ability to impact the effort for better or worse. XP, based as it is
on values of simplicity, communication, feedback, and courage, helps
stakeholders understand their roles, and offers them specific techniques to help the project succeed.
This book follows the chronology of a typical project, describing the
XP practices that apply at each stage. In the introduction, Extreme Programming (page 9), youll find an overview of XP and of the book.
Begin there, and let that chapter serve as your road map.
We became enthusiastic about XP, based on real experience on real
projects. Dig into Extreme Programming Installed. Its no panacea, but
the XP practices, installed in your team, can improve your projects as
they have ours.
Preface
Chapter 1
Extreme Programming
Extreme Programming is a discipline of software development with values of simplicity, communication, feedback
and courage. We focus on the roles of customer, manager,
and programer and accord key rights and responsibilities
to those in those roles.
We are software developers. We have been involved in many successful
projects, and even in some that werent so successful. The successful
ones were a lot more fun, for us, and for our customers. The unsuccessful ones have taught us a great deal about software development.
We have had the privilege of working on a great project, with a great
teacher, Kent Beck. We were part of the shaping of the software process named Extreme Programming, XP for short. Since then, we have
been helping everyone who will listen to learn from our experience.
The first book in the Extreme Programming series, Extreme Programming Explained, covers the reasoning behind the XP process. Based on
our experience on the original XP project and the others we have
helped with, this book describes what makes XP work, day to day and
month to month.
Successful software development is a team effort not just the development team, but the larger team consisting of customer, management
and developers. Extreme Programming is a simple process that brings
these people together and helps them to succeed together. XP is aimed
primarily at object-oriented projects using teams of a dozen or fewer
9
Extreme Programming
Extreme Programming
Extreme Programming
choose among the stories with great flexibility. Theres not much limitation on what can be done first and what second. This is by design: if
you are to choose the stories for successful on-time release, you must
have the flexibility to make the choice as independently as possible.
Read more about this process in Customer Defines Release (page 71)
and Iteration Planning (page 79).
Finally, you specify tests that show whether the stories have been correctly implemented. These Acceptance Tests (page 45), whether built
by the programmers, by an independent tester, or by you yourselves,
provide confidence that the system really does what it needs to do.
Define business value, decide what to do and what to defer, and define
the tests to show that the system works. These are your key responsibilities as the XP customer.
12
Extreme Programming
Base the program on simple, clear design. This lets you produce quality software quickly. Theres more discussion of this in Code Quality
(page 103), and A True Story (page 257). As you learn more about
what the design wants to be, improve the design using Refactoring
(page 95).
XP isnt slash and burn programming, not code and fix, not at all.
Extreme Programming is about careful and continuous design, rapid
feedback from extensive testing, and the maintenance of relentlessly
clear and high-quality code.
Keep the system integrated at all times, so theres always a good version to look at. Keeping integrated lets you go rapidly without
stepping on each others toes. See Continuous Integration (page 96).
Share the ownership of all the code, so no one has to wait and everyone feels able to make everything better. See Collective Code Ownership
(page 93), andReleasing Changes (page 145). Share a single Coding
Standard (page 97) as well, whether you evolve your own or adopt
one from elsewhere. Make everyones code look alikeit helps with
communication and team focus. Express your individuality in the way
you wear your XP ball cap.
Make sure that the system always works, using comprehensive unit
tests of your own making, as well as the customers acceptance tests.
These tests allow rapid change, and support collective code ownership
by keeping change from introducing mistakes. See Unit Tests
(page 113), Acceptance Tests (page 45), Everything that could possibly
break (page 265), and Test-first, by Intention (page 129).
Write all production code in pairs, for maximum speed and cross-training, in support of shared code ownership and rapid progress, as
described in Pair Programming (page 107).
Extreme Programming is an approach to software development that
lets programmers do what they do best program while giving the
customers what they need most business value. Its a win-win
approach and fun too.
13
Extreme Programming
14
Extreme Programming
When the date is chosen, prepare the ground. Arrange a room, send
out the invitations, order the refreshments or cause these things to
be done if you have administrative help.
Before any planning meeting, check with the customers, reminding
them to be ready and to bring any new stories, and so on. If they need
help, provide it.
During each meeting, you may wish to coordinate or facilitate or
designate someone to do so. Help to keep the team on process, make
notes on the proceedings, offer to get special resource people if theyre
needed, and so on.
After each meeting, if reporting needs to be done, you should do it or
cause it to be done. (Internal reporting generally is not needed. The
plan is on the white board and in the minds of the team. But some
stakeholders outside the room may need to be kept up to date.)
During the iteration, its the same: cause the right things to happen,
coordinate the activities, report results and always remove obstacles.
The project manager usually has the personnel responsibility, and this
is a very important one. Even on the best teams, there are differences
between individuals, and sometimes there can be temporary or permanent people problems.
When people get in conflict, you need to fix it. If someones behavior
is harming the team, you have to address the problem. If the individual
cannot or will not correct the behavior, you must remove them from
the team. This should not be done lightly or precipitously, but sometimes it must be done, and it is the project managers responsibility.
There can sometimes be political problems that impact the team.
These are major obstacles and the manager leaps in to resolve them. A
stakeholder may have difficulty allowing the customer to schedule the
stories, or may put pressure on the programmers to adjust their estimates. Watch for outside forces that can impact your team. Thats
when you need to step in, firmly and productively.
15
Extreme Programming
On the good side, the project manager gets to give rewards. There is
the annual rating and salary adjustment ritual. We cant tell you how to
do this extreme teams are all over the map on compensation policy.
Its the managers responsibility to have fair and consistent assessments
of the staff, and to have compensation fairly reflect those assessments.
And think about small rewards as well. Recognition is important. New
toys or tokens for the team. A round of Laser Tag, a round of beers, a
night at the opera. A little time off from work, and off the books. And
dont forget the families.
This only scratches the surface. The project managers role is very
important to the project. If done creatively and effectively, it can
greatly ensure the teams success.
Cause, coordinate, report, reward. And always: remove obstacles.
Rights / Responsibilities
Extreme Programming tries to provide certain benefits to
the managers, customers, and developers involved in a
project. We express these as rights because they are very
important to the success of the project, and to the team
members.
Editors note: we need these two rights tables in little boxes, like cards.
If they arent, its because I didnt figure out how to do it yet. Please
help.
16
Extreme Programming
Programmer Rights
1. You have the right to know what is needed, with clear declarations
of priority.
2. You have the right to produce quality work at all times.
3. You have the right to ask for and receive help from peers, superiors,
and customers.
4. You have the right to make and update your own estimates.
5. You have the right to accept your responsibilities instead of having
them assigned to you.
This book is about helping your project deliver these rights. Heres a
bit of discussion about why each of these proposed rights is beneficial
to a successful software project, and how XP helps to provide that
benefit.
Extreme Programming
You have the right to get the most possible value out of
every programming week.
Having a plan isnt everything, but planning is. Project time is short,
and you need to be sure that the right things are happening every
week. Iteration Planning, page 79, describes XPs short-range planning component.
Extreme Programming
You have the right to ask for and receive help from
peers, superiors, and customers.
Sometimes programmers get buried in the complexity of their work.
Help from colleagues and managers can speed things up and get things
back on track. In XP, we recommend an On-site Customer (page 31) to
be sure that requirements are understood. We use Pair Programming
to provide constant help. We offer some additional support techniques
when we discuss the The manager role (page 14). But the fundamental
rule is this: no one can refuse to help a team member who needs it,
ever.
You have the right to make and update your own esti19
Extreme Programming
mates.
The most critical factor in the success of your project is knowing when
you are going to be done. By knowing how long it will really take
not just how long you hope it will take you can guide the project to
success by managing what is worked on. XPs Customer Defines Release
and Iteration Planning allow you to do that management. Having the
programmers do Story Estimation (page 51) gives you the information
you need to steer the planning.
Project flow
The rest of the book follows the chronological flow of an XP project.
Weve pointed to many of the chapters earlier in this introduction. An
XP project begins with an on-site customer, who provides the stories
that define the system and the acceptance tests that prove the system
works. We focus on small releases, each one defined by the customer.
We work in short iterations, again working on the customers stories of
highest business value.
Programmers follow a number of important practices, including Simple
Design (page 93), Refactoring (page 95), Collective Code Ownership
(page 93), and Pair Programming (page 107). They write their code
including extensive Unit Tests (page 113), ensuring consistent progress
and high quality.
20
Extreme Programming
Based on the early iterations, the team uses Experience improves estimates (page 155) to predict future performance, which sets the project
up for success through constant informed Steering (page 171).
There will be a few defects (no one is perfect) and well tell you how to
deal with them in Handling Defects (page 183).
Finally, we include some Bonus Tracks (page 205), essays and ideas we
couldnt bear to leave out even though they dont fit exactly in the
chronological flow. We paid a lot to learn those things, and wanted to
share them with you. So dive in and check out Extreme Programming
Installed!
21
Extreme Programming
22
Forward
--Dan Rawsthorne
I have been looking at XP for a while, and have talked to a lot of people (including Ron Jeffries and Kent Beck) about it. And I think that a
lot of us are missing the point of why XP works. Quite simply, I think
that XP works because it is Validation-centric rather than Product-centric. "Huh?" you say.
First, what do I mean be Validation and Production? Well, Production
is the act of actually constructing some Product, and Validation is the
act of assuring that this Product actually does what it is supposed to
do.
Typically, Validation means that somebody other than the producer
analyzes the Product and assures that it satisfies its purpose. Now, on
with the discussion.
When developing any software system there are two questions to
answer:
Are we developing the right software?
Are we developing the software right?
Essentially, the first question is about Analysis (what is it supposed to
do?) and Validation (does it actually do it?) and the second question is
about Design and Construction (is this the right architecture? does it
satisfy the "ilities"?). Can you say Inception/Transition versus Elaboration/Construction - I knew you could...
We also know that the first question is much more important than the
second, as developing the wrong software right is useless. So, because
XP does everything to extremes, we would expect it to focus on the
first question to the exclusion of the second. Almost, but not quite...
23
Forward
Forward
My belief is that XP is the first popular process with this focus on Validation built in. It won't be last... I hope.
25
Forward
26
Chapter 2
Circle of Life
An XP project succeeds when the customers select business
value to be implemented, based on the teams measured
ability to deliver functionality over time.
Steering a project to success all comes down to what we call the circle
of life. The customers basic job is to define what has value, and the
programmers job is to build it.
Customer
build value
define value
Programmer
Figure 2.1
On an XP project, the customer defines business value by writing stories, and the programmer implements those stories, building business
value. But theres an important caveat: on an XP project, the programmers do what the customer asks them to do!
27
Circle of Life
Business value depends on what you get, but also on when you get it
and how much it costs. To decide what to do, and when, the customers need to know the cost of what they ask for. The programmers,
based on experience, provide this information. Then the customers
choose what they want, and the programmers build it. Now the picture looks like this.
build value
Customer
Programmer
choose value
Figure 2.2
Customer
define value
Programmer
estimate cost
28
Circle of Life
build value
Customer
Programmer
choose value
Figure 2.3
learn
Customer
define value
Programmer
estimate cost
We hate to be the one to break this to you, but some things are probably going to take longer than youd like. The good news is that you
can inform yourself about how fast youre going, and you can use that
information to choose the best mix of features for each release. By
managing scope, you can schedule good, solid releases for the dates
you need.
The best way to get a good release by a given date is to know how fast
the programmers are delivering features, and to use that knowledge to
choose the best mix of features possible by your chosen date. You must
manage the scope of your project.
Its tempting to put pressure on the programmers, to hold their feet
to the fire, in hopes of getting more done. If you want your software
written by people who are under stress because their feet are on fire, do
this. If you want quality to take a back seat, do this. To get the best
possibile combination of features, with the quality you need, you must
manage scope.
29
Circle of Life
Its tempting to believe your own wishes, or your own press releases,
and schedule more work than measurement says you will do. If you
want to ship late, do this. If you want to ship on time, but with a random collection of buggy features, do this. For a predictable delivery,
with the quality you need, you must manage scope.
The circle of life is profoundly important. When customers and programmers recognize that they depend on each other, the team can
steer the project so that theres always the most business value implemented at any given moment. The upcoming chapters will show you
how to get the stories that define the product, estimate story cost with
increasing precision, track how youre doing, and select the stories for
a successful release.
If what you want to do is manage your project to the most successful
conclusion, then follow the circle of life: define, estimate, choose,
build.
30
Chapter 3
On-site Customer
An XP project needs a full-time customer to provide guidance. Heres a summary of why ...
Programmers, we all know, will program anything. The trick is to tell
them whats needed. In general, whats needed is called requirements, probably to make it sound more important. In XP, we
communicate whats needed using User Stories (page 37). User stories,
written on cards, are the core of the XP planning process (the Planning
Game), and they belong to the people with the requirements. We call
these people the Customer and we ask them to be with the project
all the time. Before you read about creating user stories, heres why we
want you to show up.
The essence of what makes an XP project successful was described in
Circle of Life (page 27). The project is steered to success by the customer and programmers working in concert. An XP team wants to go
as fast as possible, and the XP value of simplicity contributes strongly
to that goal. Written specifications take a long time to write, and they
dont communicate very well. Its much more effective to have conversations about what is needed, as the project goes on.
Not every project can afford this, and other projects members fear
that they cant. But the plain truth is that the more time customer and
programmers spend together, the better things go. That doesnt mean
that the customer is holding the programmers hands, but it does
mean that being immediately available to answer questions is of
immense value.
31
On-site Customer
On-site Customer
OK, got it. By the way, are those dues figures you gave us solid
for all time?
No way, laughs the customer. Next time theres a union
negotiation, those figures will all change. Theres a story coming up giving us the ability to change them. For now, just put
them in that way.
OK, thanks, says the programmer, and returns to her desk in
less time than it took to read this.
Now yes, that same exchange could have been held via email, or written down in a detailed spec. But that would have taken more time, and
quite likely wouldnt have completely quelled the programmers concern the way the conversation did. You might also be concerned that
this important information about the requirements will get lost somewhere, but remember that you will have specified acceptance tests, and
they will surely cover the two tiers of plant guards.
You could perhaps get this much certainty by writing more down. But
you would have to write lots more, which would slow the project and
still not obviate the need for conversation. With an on-site customer,
you save time and trees, and build a rapport between customer and
programmers that serves to help you over any tough times that may
come along.
How important is it to have the customer right there? Heres an example. Ron has been coaching a project whose customers have a private
office right in the development area. A couple of times every day, while
the programmers are working, one of them will ask a question and no
one will know the answer. The programmer generally gets right up and
goes to ask Pam, the customer. In a couple of minutes, hes back,
shares the answer (because now everyone is curious), and gets back to
work.
One day on Rons last visit, the customers had to go to another work
site for machine access. They told the programmers where they were
(two floors down and a few offices over), left their phone number and
beeper number. Sure enough, in the afternoon, someone had one of
33
On-site Customer
34
On-site Customer
Summary
Having your customer with you is really valuable. Its possible to survive without it many projects do but youll go faster and more
smoothly by being together. Its the difference between being in the
car when its time to turn or just writing a note that says Dont forget
to turn at 34th Street. When 34th is blocked and youre in the car,
you can tell the driver how to recover. The note cant help.
Somewhere along the way in your project, 34th street will be blocked,
and having the customer there will bring the project back on line so
smoothly itll be as if it never happened. And every day, the small conversations will add up to a lot of trust and communication between
customers and programmers. That, of course, leads to success.
35
On-site Customer
36
Chapter 4
User Stories
Define requirements with stories, written on cards.
Customers have the right to get the most possible value out of every
programming moment, by asking for small atomic bits of functionality.
Programmers have the right to know what is needed. These two rights
come together in the User Story.
Each user story is a short description of the behavior of the system,
from the point of view of the user of the system. In XP, the system is
specified entirely through stories.
Analysis can be loosely described as the process of finding out what the
customer wants. Analysis can be done very formally, with objects and
diagrams, or it can be done very informally. XP, no surprise, chooses
informal analysis: we ask the customer.
It should also be no surprise that we don't limit analysis to the beginning of the project - what we call drive-by analysis. In XP, you do
analysis all the time. The user story is the medium of analysis the
medium of communication between the customer and the
programmer.
XP recognizes that the customer will be learning what is needed, based
on what has been done so far. By keeping stories small, releasing often,
and bringing customer and programmer together, the XP approach to
analysis ensures that what is learned can be fed back into the develop-
37
User Stories
1.
Thanks to Erik Meade for this technique! Sometimes youll have a player who resists tearing up his card. Watch for other signs of inflexibility, and find ways to help him relax into
the process. But dont touch his cards!
38
User Stories
Sample Stories
Here are some sample stories. Each one is backed up with conversation
(see Stories are promises for conversation (page 41)), and perhaps with
some related detailed information. Each one is simple enough that the
programmers could understand it, and could see how to implement it
in a week or so.
Typesetter: put each of these italicized paragraphs in a separate box, to
look as if written on a card. Consider using a handwriting or script font
- they want to look WRITTEN. Thanks!
Union dues vary by union, and are taken only in the first pay
period of the month. The system computes the deduction automatically. The amount is shown in the attached table.
When a transaction causes a customers account to go into overdraft, transfer money from the overdraft protection account, if
any.
When a transaction causes a customers account to go into overdraft, send an email showing the transaction and balance to the
customer. If overdraft protection is in effect, show the overdraft
transaction and the resulting account balances in the email.
For each account, compute the balance by adding up all the deposits and subtracting all the deductions.
Produce a statement for each account, showing transaction date,
39
User Stories
User Stories
For most of the stories above, the programmers (your authors) could
see how to implement them in a week or less. As such, we felt that we
understood the stories and could implement them. In the case of the
last story, we felt that adding special numeric fields might be difficult,
and that updating all the reports to include them was a separate effort
and might take a long time. We asked that the customer split the story,
and the customer agreed.
Note that wed really get the story split in a conversation with the customer explaining what was up not just with a note on the card. We
put the note in the text because we cant have a conversation with you.
In a real XP project, use conversation wherever you can.
41
Alistair Cockburn gave us this elegant description of story as promise for conversation.
Buy his book!
User Stories
Its better if programmers dont write stories. We want all the stories to
belong to the customer, not just in name but in their heart. There are
some times when the programmers may help the customer write the
stories. For example, if the customer doesnt know how to write stories, the programmers may need to work with her to find out what the
system needs to do. These conversations become the stories. It may
seem that you know something the customer will want. Talk to them
about it, but resist the temptation to write the stories. XP depends on
the circle of life, with customer defining and programmer building.
Dont break the circle.
It may seem that there is some large technical development that needs
to be scheduled and managed. Some teams do write these as technical
stories, but this too threatens the circle. Customers cant prioritize
what they dont understand, and all too often the technical bite is too
big to fit into a single iteration. Where possible and it usually is
you should solve this by relating the technical task back to a real customer need.
User Stories
43
User Stories
44
Chapter 5
Acceptance Tests
Surely you arent going to assume youre getting what you
need. Prove that it works! Acceptance tests allow the customer to know when the system works, and tell the programmers what needs to be done.
Customers, remember that you have the right to see progress in the
form of a working system, passing repeatable tests that you specify.
Well, heres the responsibility part of that: specifying the acceptance
tests.
Every system undergoes testing to find out whether it works as
needed. Some dont get this testing until they go into use and actual
users discover flaws for themselves. This leads to pain; pain leads to
hatred; hatred leads to suffering. Dont do that test before you ship.
Some systems put off overall testing until right before release. They
often eat into the testing time with schedule overruns, but even if they
allocate the full testing period, this slows things down. The reason is
simple: programmers forget what they did. If I write a program today
and test it a week from now, my recollection of how I wrote it will have
faded, in favor of whatever Im working on then. So when I get the
defect indication, I wont be able to guess quickly where the problem
is. This leads to long debugging sessions, and slows the project down.
Dont do that test right away.
XP values feedback, and there is no more important feedback than
early information on how well the program works. If it were possible
45
Acceptance Tests
to have the computer beep at the programmer one second after she
made a mistake, thered be a lot fewer mistakes in the world today. We
cant usually test the systems function every second (but see Unit
Tests, page 113, for a discussion of how hard we try). With acceptance
tests, the sooner we get them, the sooner we can make them work.
The customer responsibility is to provide those acceptance tests as part
of each iteration. If you can get them to the programmers by the middle of each iteration, the project will go faster. You will get more
business value by the deadline. Thats a promise.
There are many different ways to implement the acceptance testing on
your project, and the programmers will pick one. Well talk about that
below. In any case, you need to specify the tests.
What must I test, youre probably asking. The official XP answer is,
you only have to test the things that you want to have work. Lets be
clear about that: if its worth having the programmers build it, its
worth knowing that they got it right.
Some projects have a legacy system they are replacing, and they can get
their test data from the legacy. In this case, your job will be to select
the legacy inputs and outputs you want tested. Some projects use
spreadsheets from the customer that provide the inputs and expected
outputs. Smart XP programmers will extract the information from the
spreadsheet automatically and read it into the system. Some projects
use manually-calculated values that are typed in by someone on the
team.
Some customers give input numbers to the programmers, and check
the output by just reading it. There is an important issue with this one
that has to be mentioned. This is an anti-pattern a bad idea called
Guru Checks Output. Checking the output of a computer is very
error-prone. Its easy to look at the numbers and decide that they look
correct. Its also easy to be wrong when you do that. Far better to have
the expected answers up front, even if they have to be hand-computed.
One more thing. The rights refer to repeatable tests. All tests in an XP
project must be automated. We give you the ability to move very rap46
Acceptance Tests
idly, and to change your requirements any time you need to. This
means that the code will be changing rapidly. The only way to move
rapidly with confidence is to have a strong network of tests, both unit
and acceptance, that ensure that changes to the system dont break
things that already work. The acceptance tests must be automated:
insist on it as your right.
We arent much into dire warnings and predictions, but heres one
thats a sure thing: the defects in your system will occur where you
dont test. Push your acceptance tests to the limit, in breadth and in
depth. Youll be glad you did.
Acceptance Tests
it once to define a test. Spill output to files and check them automatically.
Use simple file-based tools like grep and diff and Perl to check results. You can get a lot of testing automated very quickly with these
tools.
Always build your acceptance tests to be automatic, but build the automation simply and incrementally as you actually need it. Its easy to get
sucked into investing in test automation instead of business value. Get
them automated, but dont go overboard.
Timeliness
Acceptance tests really need to be available in the same iteration as the
story is scheduled. Think about it you want to score the development based on getting stories done, and the only way to know if they
are really done is to run the tests.
Programmers, you have the right to know what is needed. Insist on
this right in the form of automated functional tests. Youll be glad you
did.
Customers, you have the right to see progress in a running system,
proven to work by automated tests that you specify. Insist on this right,
and do your part by providing the necessary information.
48
Sidebar - Chapter 5
49
Same as previous test, except that emails should be sent. Send them all
to a fixed account: have the programmers write code that reads them
and checks their formats, so the test can be automatic.
Produce a statement for each account, showing transaction date,
number, payee, and amount. A sample statement is attached
make the report look approximately like the sample.
Its tempting to look at the report manually. That way lies the dark
side. Check the report once, very carefully, then have the programmers
machine check it against the good one thereafter.
When the GPS has contact with two or fewer satellites for more
than 60 seconds, it should display the message Poor satellite contact, and wait for confirmation from the user. If contact
improves before confirmation, clear the message automatically.
Functionally testing small hardware devices can be tricky. Do you have
a version of the hardware hooked up to testing equipment that can
read the display, provide fake satellite input, and so on? Depending on
your cost of testing and need for reliability, this might be valuable
enough to do.
Allow the user to add new service types to the systems initial list.
For example, he may wish to add a special entry for getting the car
washed at the high schools free wash. Include the standard fields
amount and date, plus allow the user to add any additional text
or numeric fields. Reports should automatically sum any numeric
fields. (Programmer note: story needs splitting. Please separate
text and numeric fields into two stories, plus one for the summing.)
This program, probably conceived as just an interactive GUI-based system, clearly needs a programmatic interface. Its not hard, given even a
somple interface, to have a little scripting language set up that simulates GUI commands and checks report output. Remember to
compare the report file to a correct one rather than check it by hand.
50
Chapter 6
Story Estimation
Customers need to know how much stories will cost, in order
to choose which ones to do and which to defer. Programmers
evaluate stories to provide that information. Heres how.
If all stories were the same size, it would be easy to steer the project.
Wed just do some of the most important stories, and make note of
how many we could do during an iteration. Then wed just use that
number to set our expectations for next time, and to select what to do
by our preferred delivery date.
Well, were doing about five stories per week, and there are
ten weeks till Comdex. Well probably get about fifty done.
Right now, it looks like these are the ones well pick. To make
sure were always in the best possible shape, well do the most
valuable ones first. Here are the best ten, lets do those over the
next two weeks.
After each iteration, wed see how fast we were going, and adjust
accordingly. And if our priorities changed and we brought in ten
entirely different stories next time, that would be great. It would just
make the product even better.
How fantastic this is! If we know how fast development is actually
going, and how difficult the upcoming work is, we can have the best
possible outcome our time and money can produce!
51
Story Estimation
Well, all stories arent usually quite the same size, but as the team goes
along, youll get better and better at knowing how big they are. Some
may be worth one point, some may be worth two or three, some only
one half. If the team is doing five per week, its just as easy to pick the
most important ten points worth as the most important ten stories. As
the project progresses, estimates will get better and better, and your
ability to steer gets better too.
Its not easy to know exactly how fast you will go at first, but its easy
to observe how fast you do go. Then, except for obvious adjustments
like vacations and holidays, its best to trust your actual speed and base
your planning on how fast youre actually going.
Our mission here is to describe how to estimate stories. During the
course of the project, its best to do that comparatively. At the beginning, when you have no direct experience, there are some tricks you
might want to use. Well start with comparison.
Story Estimation
same way. But, it turns out, that doesnt work. The actual time to
implement a story is made up of two components how difficult the
story is, and how fast the team is going.
Back when you implemented the first story, perhaps support requirements were low and there werent other projects coming down. The
programmers spent most of their time programming, and they got the
story done in a week. But now, there are support requests coming in,
new projects to plan, and lots of meetings going on. That same story,
today, might take two weeks or more. Knowing that our new story is
the same as one that took a week is good, but it isnt enough.
Heres what to do. Well estimate story difficulty, using a simple point
system. Local naming rules for these points apply. Some teams call
them perfect engineering weeks, but other teams find this causes too
much pressure trying to fit perfect weeks back into the real weeks that
wind up being issued to us. Some projects call them Gummi Bears. No,
really. You might prefer Story Estimation Units, or Bucks. Rons favorite name, this week, is just to call them points.
Youll see in a bit that we recommend doing initial estimates by thinking in terms of time. Pass over that for now, and just accept that all the
stories you have worked on are all classified, in points, somehow. Then,
to estimate a new story, pick a completed one that is comparable. If it
seems the same, give it the same number of points. If it seems twice as
hard, give it twice as many. Half as hard, half. Its simple, and its easy.
The conversations go like this:
Jill says, I think this is just like that one a couple of iterations ago, the
historical report, where we had to connect to the database, but also
had to output those files.
Jack replies, Yes, except this one we have a lot more files. I think this
one is harder.
Youre right. Probably about fifty percent harder. How many points
was the historical report?
53
Story Estimation
Jack, flipping through cards, finding the historical report, It was a one
pointer. Lets make this story one and a half.
It really becomes that simple. A quick discussion about what old story
the new one is like, maybe a check of the old card to see how many
points the old one was, and youve got an estimate. The team is doing
many stories over many iterations, and gets very good at this.
Its always best to estimate in pairs or groups up to four works just
fine because having someone to talk with makes it easier and more
accurate. The give and take helps a lot. Well talk more about this in
Customer Defines Release (page 71), and Customer Defines Release
(page 71). Lets move on now to getting those initial estimates.
Story Estimation
OK, give it three points, but consider asking the customer to split the
story down into two or more. And our advice is that if you start thinking you could do it in a month, your intuition has become too fuzzy. If
your best estimate is four weeks or more, please have the customer
break the story down.
As soon as you have estimated the points for a few stories, start doing
it both ways. Ask your intuition about its difficulty, get the points that
way. Then compare the story to the others, asking yourselves which
ones its like in size. Check the points, see if you get the same answer.
For a new project, with fairly experienced programmers with reasonable intuition about the application, a team can go over a hundred or
more stories in a day or two, and rate them by difficulty.
It usually turns out that your initial ratings will be pretty accurate. But
whats more important, as you remember from your rights on page 17,
is that you can change those assessments at any time. When you learn
that something is easier or harder than you thought, you get to update
the ratings on cards that are similar. The majority of times, youll be
rating stories as easier than you feared after all, the whole team is
learning, and for lots of stories, youll even have built little tools.
Sometimes, though, you may need to upgrade the storys difficulty.
Thats not a bad thing, because the truth is never a bad thing. Knowing the cost of things is how an XP team steers the project to success.
Spike Solution
It really is easy to estimate the difficulty of stories compared to other
stories. Brainstorm what the tasks are a bit, then see what youve
already done that is about that size, or twice the size, or half, or
one-and-a-half, as we described above.
But what if you havent done anything like this story before? What if
its the beginning of the project and you havent done anything at all?
The answer is simple: do some experimenting. We call such an experiment a spike solution, to remind us that the idea is just to drive
55
Story Estimation
through the entire problem in one blow, not to craft the perfect solution first time out. You need to know how long it will take to do
something. To know that, you need to know how youll go about it,
but you dont really need to have done it all.
Here are some examples. None of these are made up they are actual
descriptions of spike solutions that people have used to learn how hard
something was.
Balancing an account.
We are going to have accounts, like bank accounts, with transactions in them. We will need to compute the account balance.
This example was actually done live, by Ward Cunningham and
Kent Beck, at an OOPSLA conference a few years ago. The first
spike solution was to take a collection of numbers and add them
up. Sounds dumb, doesnt it? But thats the essence of getting
the account balance: take the numbers and add them up.
We mention this one first because it is so primal and simple. By
doing this experiment you realize the fundamental simplicity of
getting the account balance: just add em up. It pulls away all
the separate issues of the Transaction class and the MonetaryAmount class and the ACID properties of the database, and lets
us see balancing for what it is: get all the stuff and add it up.
Naturally the spike doesnt stop here. We might build a little
Transaction object with an amount in it, make a vector of them,
loop, add em up. We might even make a little Monetary
object, put it in the Transaction, make a vector, add em up. By
this time, were convinced: balancing an existing account will
take less time to code than this description took to write up.
Formatted reports
We are going to have a bunch of formatted reports. They will
have different columns, and they all have to be totalled and subtotalled. Maybe we dont have a reporting tool maybe we
do. In either case, we need to estimate these reports. So we
56
Story Estimation
spike.
The spike? Make a collection of record objects objects with
data in them but no behavior. Give them a key field and a couple of values. Code the report, using whatever tools you have.
First just print em, to get a feel for the shape of the loop. Then
print a total at the bottom. Then print a subtotal on each
sequence break. This whole experience will probably take an
hour or two. So the basics of reporting are easy.
Now look at formatting. Use your tools to format some numbers and dates in a few quaint and curious ways. See how hard it
is to do.
Based on the report descriptions, number of fields and keys,
and the hassle of formatting, estimate doing a report. Multiply
by the number you have to do. (Id assume the customer wont
like any of the reports the first time and will change them an
average of once each.)
If there are a lot of reports and the cost seems too high, do an
experiment with a report generator or some table-driven thing,
so you can see whether the customers can do their own reports.
Keep it simple, no more than a day.
Database Access
While it runs, the system needs to access your SQL database to
find the details for each item it processes. You want to know
how long it will take to code this, and you also want to know
how it will perform, in case you have to do something special.
You need a sample database to access. Anything will do. Write a
simple SQL query that will return a few records. Test it in interactive mode. Code it into a program and send it across through
your database connection. Note what goes wrong. Probably
you wont get it across for a while, then probably you wont be
able to deal with what comes back. Might take a day or so to
get the first one working. If youve got experience and good
DB connection software, it might just be an hour. After an hour
or a day, you know what the code looks like to talk to the DB.
57
Story Estimation
Automatic Email
The system has to email the support people when certain things
happen, so as to beep their beepers. How hard will this be? No
biggie to detect the error or format the message. We can estimate that. But it could be awful to send the email, weve never
done that.
I just surfed the web, looking for email protocol. Item 22 on
my list is a Java applet that tells me about the SMTP protocol
and lets me type in example lines. Looks like it is all done with
text messages. Should be easy.
Write a little program to connect to the email API on your
machine, and send a simple email to yourself. It probably will
barf. Debug it. After an hour or so, or a day or so, youll get it
to work. Now you have the sketch of the code for doing email,
and you can estimate the story.
Story Estimation
In this case, you are not here to drain the swamp, youre just here to
kill one alligator. As soon as that gator is dead, and you can estimate
how long the solution will take, move on
Estimation Summary
We programmers estimate stories in points, based on perfect engineering time, and we keep track of how many points we can do in each
iteration. That lets our customer steer us to success by choosing the
best combination of stories within the time and money available.
Except at the beginning, most stories are best estimated by comparing
them with other stories already completed, and giving them points
according to their relative size. It turns out, as youll find, that programmers are generally very good at making this comparison.
Sometimes, at any stage in the project, stories will come along that
youre not ready to compare. In this case you do a Spike Solution, a
quick experiment that prepares you to estimate.
Even the strangest stories will yield to a little creative brainstorming.
For some whimisical evidence of this, check the bonus track How to
estimate anything on page 217.
At the beginning of the project, use your group intuition to get that I
could do that in a week feeling, then set the initial points based on
that intuition. We recommend giving the points a neutral term, rather
than weeks, just because it keeps the tension down a bit as you track
your implementation velocity. As soon as you begin to get experience
with the relative difficulty of the stories, you can, and should, update
the points for the remaining ones. This gives the customer the best
opportunity to steer you to success.
59
Story Estimation
60
Interlude
Sense of Completion
XPs nested planning and programming cycles keep the
project on track, and provide a healthy sense of accomplishment at frequent intervals.
Most projects go on for months; some go on for years. To keep from
going mad with the never-ending pounding out of code - even beautiful well-crafted code - every project needs punctuation. The best
punctuation a programmer can get is a sense of completion. XP's planning cycles provide a rhythm of cycles within cycles, each with its own
moment of completion.
Running the tests successfully gives the programmer a sense of completion every few minutes. Share this small joy with your partner.
Finishing a task provides a sense of completion every few hours. Share
with the other programmers; take a break; maybe switch partners.
Completing a story is an important milestone. Each one provides a
sense of completion. Share with customers and programmers; maybe
have a small ritual.
Wrapping up an iteration completes several stories and opens the door
for the next accomplishments. Share with the whole team; consider
bringing in pizza or some other little celebration.
Each release provides a major sense of completion: new business value
is in the hands of the customer. This is a good day! Break out the
champagne!
61
Sense of Completion
62
Sense of Completion
63
Sense of Completion
64
Chapter 7
Small Releases
The outermost XP cycle is the release. Small and frequent
releases provide early benefit to the customer while providing early feedback to the programmers. Here are some
thoughts on how to make it happen.
If your customer knows now just exactly what she wants, and if by the
time youre done, shes still going to want the same thing, it may be
the first time in software history that this has happened. Probably there
will be a prize for you somewhere. Its much more likely that as you
steer the project, youll be changing direction, a little or a lot. As you
find out whats easy to do and whats more costly, youll be making
better and better decisions about what to do and when to do it.
One of the most important things you can do on an XP project is to
release early and release often. If possible, wait no more than two
months to release a version of the software, and release every couple of
months thereafter. And we dont mean a demo version, we mean an
actual version that does something useful. Even though you dont
really have to release for six months or a year, releasing every couple of
months can really pay off. You dont want to pass up the chance to
learn what users really want. You dont want to pass up the increasing
confidence that will come from showing people that you have done
something useful. And you dont want to pass up the sheer thrill of
releasing useful software into the universe.
Even though youd like to, we know that small releases ares impossible
in your situation. We accept that you just couldnt do it. But just imag65
Small Releases
ine for a moment, that you could actually get some useful subset of the
software into the customers hands. Not something theyd demo and
comment on and set aside, but something theyd use every day. They
would learn a lot about what they really wanted, and youd be that
much more capable of steering the project to success.
Even better, if the releases are actually useful, youre delivering real
business value to the customer, which will keep them happy and keep
them coming back. It will build confidence and keep them supporting
the effort, even if once in a while things get rough.
OK, youre convinced that it would be nice, but it just couldnt happen with your product. Your product is all-or-nothing, just couldnt
really be useful except when its really pretty done. Well, believe us, its
worth thinking about it. Of all the projects weve been involved with
that failed, almost all of them would have been successful had they
delivered a little functionality over time, instead of waiting and waiting
and waiting. So lets take some examples of projects that couldnt possibly deliver something early, and try to think of things we could
deliver early after all. You probably wont be so lucky that well pick
yours and solve it fact is, you know more about your project than we
do but practicing on ours may help you find your own small releases.
Small Releases
Personnel System
Youre replacing your personnel system with a new one. Obviously you
need an integrated database and cant release the system until it does
everything the old one does, plus all the new things youve thought of.
Theres just no way you can release this incrementally.
67
Small Releases
This could turn into one of those horrible tail-chasing exercises where
theres always just one more feature that you have to put into the new
system before its ready. Just dont go there.
Instead, what if we made our database compatible with the old one,
but with new relational tables for new features that are needed, and
delivered some of those new features. We could produce new reports
that summarized the use of the new features, and we could produce
new versions of some of the old reports to show combined values.
Maybe we could do the GUI trick like from the payroll example, where
we gave the users a better way to input certain transactions. Maybe we
could even put up a little web interface and let employees enter their
own address changes and telephone numbers.
Tax Package
Heres one we wish we had thought of a few years ago. A professional
tax package isnt useful unless it does some minimum number of
forms, and the minimum is very large. So building a new Windows-based professional tax package is a multi-year investment. And
theres just no way to release just part of it.
Well, if your company already has a DOS-based package thats very
comprehensive, how about putting a Windows GUI on top of it, and
use that calculation expertise until you get the more powerful
object-oriented incremental calculation engine working?
How about using individual forms calculations from the DOS program
and replacing them incrementally with the new engine?
How about using the existing forms print capability of the DOS version, together with its non-WYSIWYG output display, until the screens
that look just like tax forms are done?
68
Small Releases
You are building a new micro-computer-based distributed factory control system. There will be these cool little micros at each station, all
networked together, cooperating to control the entire factory. You
need control modules and control programs for all the machines that
might be there in the factory. And you need a very sophisticated distributed object system to make sure it all works. Theres just no way
you can release anything early.
Well, how about releasing a single module that controls some specific
machine, and that plugs into the legacy system, emulating an old-fashioned controller. Surely your micro-based system could raise and lower
a few electrical levels to make it look like the old modules, and even
respond to centralized signals telling it what to do.
Then do another kind of module, and another. Choose them so they
are likely to want to talk to each other. When a factory needs a couple
of these, lets hook just those modules together in a distributed fashion, letting the rest of the place run on centralized control.
It might be a bit tricky, and it would be wasteful in that when the last
distributed module went in, all that centralized control code would be
unnecessary. But in the years between the ability to release one little
controller, and the release of the last bit of the fully distributed system,
you could make so much money and learn so much!
Small Releases
of the problems with this system is that not all planes would be smart
enough to do this, and what would happen if a plane lost its ability to
sense and be sensed by the others.
Would it be possible to dedicate certain altitudes and flight paths to the
new planes? Would it be possible to have on-ground control computers watching for planes that couldnt communicate, and either
controlling them from the ground or handing them back to the existing legacy ATC?
Summary
We hope youre getting the idea. Inside almost every large program
there are lots of little programs trying to get out. You might have to do
a little extra work around the edges to get these pieces useful on their
own, but it can be well worth your while. Youll learn lots more, and
you will actually be delivering value. Would that be cool, or what?
So put all your thoughts behind this simple idea: release little bits, to
be used by real customers, very frequently. It will allow you to deliver
the most value in the shortest time, with great confidence and low
stress. We also think it will grow new hair on your head and help you
lose weight, but were not sure about those two. The rest were sure.
70
Chapter 8
71
In that same exploration phase, the programmers will be experimenting with ways of building the system, trying experiments that inform
them how costly the various stories and features will be.
Most teams remember to do the exploration part of writing the stories,
since its hard to proceed without them. But dont forget the programming part of exploration take a week or so to experiment with the
application before trying to proceed to commitment.
The exploration activities culminate in the commitment phase of the
planning the release. It goes like this, and the tune is our own
invention:
Youll hand your story cards over to the programmers for estimation.
Then you sit back and listen, and wait for questions. If the programmers want to know whether you want a Windows-specific GUI or one
that is web-based, youll answer them. (Sometimes youll have to get
them to explain their question first. Thats OK, keep after them until
they do.)
The programmers are trying to estimate the difficulty of each story
card you have given them. Theyre doing that so that you can decide,
based on business value and implementation cost, what should go in
the next release.
Sometimes the programmers will find one of your stories too hard to
estimate. That doesnt mean you cant have it, it just means that its
got too much in it for them to make a valid single estimate. This is
important to you: you want the estimates to be as good as possible, so
that your selection of what to do and what to defer is as good as
possible.
Sometimes you just have to explain what you meant in the story. When
this happens, consider ripping that story up and writing a new one. It
feels good and shows the programmers how flexible you are.
Sometimes, the story is just too big. In XP, the programmers arent
allowed to estimate things in months of effort. Weve learned that
72
those estimates are too often wild guesses. So even if the programmers
are pretty sure about a big story, we dont let them estimate it that way.
Instead, theyll ask you to split a story. Often this will be obvious and
easy. You asked for a lot of things in one story. Just split the things out,
tearing up the old card (feels good, doesnt it?) and writing new ones.
If, while youre at it, you can keep things of like priority together, that
will help later. An easy way to do that is to choose the most important
thing, write it on a card, then the next, and so on. Dont worry about
getting too many card. Too few is a problem, but if there are too many,
you can just clip them together.
Listen to the programmers as they estimate your stories. Theyll be
talking about technical things, but youll usually get the drift of what
they intend. That will tell you, in turn, whether they are understanding
what you want. You may hear, from time to time, things that make you
think maybe they dont understand the story. If that happens, stop
them and inquire. If theyve got it right, fine, but if not, give them the
straight story and let them carry on. You might want to tear up the
card and improve it, of course. Feel the power of change? Wonderful,
isnt it?
After a while (and the first time around it could be a long time), the
programmers will have assigned a cost number to each story. Different
teams call this number different things: Difficulty Points, Perfect Engineering Weeks, Bucks, even Gummi Bears. Whatever the name, these
numbers are the same thing: estimates of how difficult each story is to
build. With just one more fact, youre ready to choose the stories for
the release plan.
To know what to schedule for the first release, you need to know how
fast the team can implement stories.
What?, you may be saying. I need all these things done by the release
date. I want it all. Well, as the song goes, you cant always get what you
want, but if you try, you can get what you need. Heres how you do
that.
73
The programmers will tell you how many points they can do in a given
period of time. We call that number Project Velocity. If theyre estimating with perfect weeks as the basis, theyll probably do one point per
programmer, every two or three calendar weeks. If theyre estimating
in perfect days, theyll probably do one to three points per programmer per week. (Dont get excited, those guys arent going faster,
theyre just measuring feet per minute instead of miles per hour.)
At the beginning of the first project of this kind for the team, this
number will be a pure guess. But as soon as you get experience doing
the stories, the team will measure the actual velocity. You can use that
experience-based number to steer the release. And thats your job.
Once the stories are all estimated you have a bunch of story cards back
in your hands, with business value that you understand, and difficulty
points of one, two, or three. Sometimes one and a half, but dont
worry, someone in the room probably has a calculator. The velocity is,
say, five points per two week iteration.
You know how many iterations there are between now and the scheduled release date. Suppose there are six. Then you should plan to get
about thirty points done by then, five times six. Go through your cards
and pick the ones with highest business value that add up to no more
than 30 points. Thats your plan.
Sounds easy, doesnt it? Well, it is easy, except for one thing. You may
well wish you could have 35 points instead of 30. In fact, you surely
will wish that, since all things being equal, more features are generally
better than fewer.
Our advice is to go with the numbers. If the numbers say you can do
five points per week, and you could get your 35 total points if the team
could just do six, resist your temptation to plan for 6. Do work to get
the teams velocity up. But plan based on your actual speed, not your
hopes. That keeps your plan closer to reality, and keeps you focused on
your most important role, steering the project to success.
74
The team will go faster if its winning than if its falling short. Give the
team a chance to exceed their goals they may surprise you. And your
own experience of the project will improve as you learn to guide it to
success.
As the customer, you define the release by selecting the best combination of stories that the teams performance suggests can be
accomplished. As you learn more about performance, and more about
how the system is shaping up, youll adjust and tune the combination
of stories you request. An XP team will always adjust immediately, and
work on just the things you need to make the system as good as it can
be within your time and budget.
75
for the best release by the date. That selection of stories makes up the
release plan.
Some teams find it interesting and comforting to lay the cards out
against the calendar in the first iteration, well probably do these 10
points, in the second these, and so on. Experienced teams dont even
bother, because they know that the priorities will change and that
theyre completely comfortable working on whatever the customer
comes up with.
Either way, the main thing to remember is this: this is a plan, an estimate, not a fact. What will happen isnt just what you laid out here.
Itll be a lot like that, but itll be somewhat better or somewhat worse
for most projects. Once in a while youll get really lucky and do lots
better, and sometimes you might not come close.
However it goes, the good news is that you dont have to wait till the
end. Remember that in the iteration plan, every couple of weeks, you
have a chance to reassess where you are and how fast you are going. So
you have every opportunity to steer your project to success.
77
78
Chapter 9
Iteration Planning
Inside each release, an Extreme team plans just a few weeks
at a time, with clear objectives and solid estimates.
As the XP customer, you have the right to get the highest possible
value out of every programming week. XP projects work in short iterations of two or three weeks, and you select the work to be done in
each of those iterations. Your mission is to select work that will maximize the business value completed by the end of the iteration.
Supporting your customer rights, the programmers agree to work on
the stories that you define, in the order you request. For you to do the
best job of steering the project, you and the programers need to plan
the work in short chunks that we call iterations, including tighter estimates of the work effort than were provided for release planning. The
process goes like this:
During release planning, discussed in Customer Defines Release
(page 71), you considered the business value of each story, while the
programmers assigned Difficulty Points to each story, and they told
you their estimated velocity, also in points. Perhaps your team has a
velocity of 30 points per iteration. To prepare for the iteration planning meeting, select from all your stories, your favorites, up to a total
of 30 points. Pick out a few extras, just in case. Many customers bring
all their story cards to the meeting, with the ones for this iteration on
top of the stack.
79
Iteration Planning
Your role in the meeting is to present and describe the stories one at a
time, while the programmers will quickly define programming tasks for
each story. When all the stories have been presented and tasked, the
programmers will sign up for work, and estimate the tasks. If theres
too little or too much to do based on the stories you bring in, you get
to decide which ones to add or remove.
During iteration planning, therefore, the conversation swings back and
forth. You explain a story, with the programmers asking questions. As
they begin to understand the story, the programmers brainstorm the
tasks for it, and put them on the board. Then you go to the next story.
When all the stories have been explained and tasked, there is a brief
flurry of activity while the programmers sign up and estimate the work.
Usually at the end there is some balancing to be done. Programmers
with too much to do trade with those who dont have enough. And
often, you will need to help out by removing some less important work
from the board. Occasionally youll even get to add more. In all cases,
its most effective to do the adjustment rather than try to cram just a
little more in. It is tempting to push the programmers to try a little
harder, and usually theyll give in at the slightest push. But in the end,
their actual velocity, not their good wishes, are your best friend in
steering to success.
If you are planning to meet someone for dinner, in front of their hotel,
and it will take you a half-hour to get there, it wont help to tell them
itll be fifteen minutes. Theyll just have fifteen anxious minutes of
waiting. Its better to plan your dinners, and your projects, based on
your best measurements of actual performance.
The team wont lay back. When they get things done early and often
they will theyll ask you for more to do. When thats the way you
work, everyone gets to feel good. And folks who feel good work
together better.
80
Iteration Planning
Iteration Planning
Iteration Planning
sign up for all the tasks on a story, rather than picking and choosing.
The reason is that itll help ensure that stories get fully completed.
Suppose that story A has 10 points worth of tasks in it, and I sign up
for seven of it and you sign up for three. Well, you might work on
other important tasks, especially if they add up to a story, and put the
three off. That could put story A in jeopardy. How would the team
notice this problem?
You could have programmers accept responsibility to watch stories,
even if they dont sign up for all the tasks. Then the programmer who
owns the story might wander over and coordinate getting the three,
but not all programmers are assertive enough to do this. Instead,
theyll wait, or work on something less important, rather than get their
story out.
You might get lucky. Someone else might notice the three tasks not
getting checked off the board and raise the issue, but if no one is on
the hook for the story, it may not get noticed.
If no one feels responsibility for the story, then only the tracker is likely
to notice problems. This puts a complex burden on tracker to notice,
and to cause tasks to be reallocated. This isnt a good thing. Far better
to have a single programmer feeling responsibility for each story. The
simplest way to do that is to sign up for whole stories where possible,
and to have an individual feeling responsibility for the whole story even
if she hasnt signed up for all the tasks. Thats what we recommend.
If there are tasks on the story that you just cant do, then pair with the
person who can do them. That way youll learn something and will see
to it that you story gets done. If its physically impossible for you two
to work together, you have to fall back on far less effective approaches,
like following up, nagging, begging, and so on.
One more point on signing up for stories. What if the task brainstorming done by the team isnt sufficient to complete the story? What if no
one remembered that you have to create an input record format? Well,
83
Iteration Planning
we hope someone will notice, but if theres no one on the hook for the
whole story, chances are too good that no one will notice.
Notice also the connection to Collective Ownership. Normally if you
need something done, you and your partner just do it. When theres
an artificial division between the things you can and cant do, the
whole process slows down. Wherever possible, avoid having specialists.
Theyll just become bottlenecks. Turn them into partners and expert
helpers, instead.
84
Iteration Planning
Now its time to sign up. Programmers who are particularly interested
in some area jump up and put their initials on the board by the things
they want to do. In more civilized environments, you might ask for
volunteers, but its more fun to scramble. Other programmers who
dont care what they work on this iteration will hang back and pick up
whatever is left over. If youre a newer member, its usually a good idea
to sign up early, so you can balance your need to learn with what you
already know.
It is always appropriate to ask another programmer to help you if you
sign up for some particular thing. That programmer will always answer
yes its a rule.
As programmers sign up, they estimate each thing they sign up for.
They stop signing up when their estimates reach their capacity for this
iteration. (See Project Velocity.)
If there is too much on the board, the customer decides what to take
off, and adjustments are made to signups. If there is too little, the customer adds more stories as at the beginning. Continue until the board
is just right.
At this point, all the stories and tasks on the board are signed up and
estimated. Our original story and tasks might look like this, with Chet
signed up:
Process Union Dues Refunds
chet1.0Create format for transaction
chet 0.5Add transaction to accepted transactions list
chet1.0Create Union Dues Refund Station
Note that it isnt necessary that a single programmer sign up for all the
tasks on a story, and sometimes theres a good reason not to. In general, though, its nice to have a single person responsible for making
sure the story gets done.
You may find another way of doing iteration planning thats better
than this one. If you do, please let us know. Just remember the three
85
Iteration Planning
key parts: Customer presents stories, team brainstorms tasks, programmers sign up and estimate.
86
Chapter 10
87
88
Chapter 11
Programming
Its called Extreme Programming, after all. Heres how we
do the programming part of things.
In the iteration plan, the team received stories from the customer,
broke them down into tasks, and signed up to do them. Heres how
that doing gets done.
An XP programmer works with a partner. All production code is written by two people, sitting together at one machine. We call that Pair
Programming (page 107). Your partners vary over time: most XP
teams switch partners multiple times per day. But for some tasks, you
will probably work with just one primary partner, switching only to
address some particular problem, or when your partner is away. And of
course, sometimes youll be helping someone else on their task.
The pair work on just one task at a time. Programming is hard enough
without trying to do more than one thing at a time. After completing
each task, the pair will integrate it into the software already released,
then run all the unit tests in the entire system, making sure that they all
run at 100 percent, and theyll then release the tests and code for their
task into the repository. Tasks are released one at a time because the
project goes best when everyone is working on the most current code
all the time. The best way to do that is to integrate often. We call that
Continuous Integration (page 96).
As the pair work, theyll proceed by writing tests first, then fixing
them to work. Test a little, code a little. Theres a long example of this
89
Programming
90
Programming
totsal = 0.0;
for ( i = 0; i < nPers; i++) {
pers = persons[i].
sal = pers.salary();
totsal += sal }
return totsal;
Now when you run across that chunk of code a few weeks later, it only
takes a few moments to figure out what it is, namely compute total salary. And if its expressed this way, its not much harder or much easier:
totsal = 0.0;
for ( i = 0; i < nPers; i++) {
totsal += persons[i].salary() }
return totsal;
91
Programming
Working in pairs like we do, and sharing ownership of all the code, its
a good idea if we all program the same way. We need to name things
similarly, so well all know where to look. We need to format things
similarly, so well all see code that looks like we expect. We need to create objects in standard ways, and so on. So every XP team needs to
have a Coding Standard (page 97). The team needs to agree on it, so
dont worry too much. Having everything look the same helps everyone go fast, so be reasonable about your favorite curly-bracket style
when it comes time to decide. Youll quickly adapt to the new standard, so no stress, OK?
As we code, we always try to use Simple Design (page 93). We do this
in two key ways. First, when we are thinking how to do something
(having already expressed our intention to do it), we think about, and
generally do, the simplest thing that could possibly work. Will an array
do? Use an array. Will an if statement do? Use one? Will a case statement do the job? Well, try to think of something simpler there
usually is something. Then, when the tests are running, we look for
duplication and simplify the entire system to be as simple as possible.
This final simplification process is called Refactoring (page 95).
Now, with the tests all running and the code simplified, were ready to
release the code. That can be a moderately complex process, and we
talk about it in some detail in Releasing Changes (page 145). The basic
ideas are simple: keep the unit tests at 100 percent, so there are no
regressions; release often, so that there will be few collisions from people editing the same classes; then resync with the rest of the team, so
that the system stays in continuous integration; use a single point of
integration to serialize updates. Good XP pairs release software multiple times per day and retest the integrated system every time. The less
time you wait, the fewer problems youll have.
There you have it. Task done, built by a pair of programmers, testing
first, expressing intention, maintaining a simple design through starting simply and Refactoring (page 95) as needed, following an
agreed-upon coding standard, and releasing code frequently to keep
everyone notching forward together. Check out some important
details below.
92
Programming
Simple Design
93
Programming
94
Programming
write as well, and of all the joys of XP, seeing this craftsmanlike simple
code emerge is one of the greatest.
To keep the code this way, we have to become good at refactoring.
Refactoring
We keep the code simple at all times.This minimizes investment in excess framework and support code. We retain the
necessary flexibility through refactoring.
Refactoring is the process of improving the codes structure while preserving its function. The definitive book on the subject is Martin
Fowlers Refactoring: Improving the design of existing code. Get it,
study it, learn it. We cant begin to do it justice here, but well tell you
a bit about how and why.
Even if you spent a lot of time designing up front, as you wouldnt do
on an XP project, the details of your design would inevitably be wrong
here and there. If you focus on delivering business value rapidly, your
system will have an even greater need to evolve. Refactoring is what
keeps you from getting wedged by your own changes. Have you ever
needed a new way to do something in the code, implemented it, and
then put off updating all the existing uses of the old way? Well, probably not, but we have, and we can tell you that it leads to code that is
hard to understand, hard to update, and contains duplication. Since
youve probably never done it dont start.
Instead, when the design wants to change, as it will, change it. Put in
the new capability you need; move the functionality to the class where
it wants to be; create the new helper class thats called for. Then bring
the entire system into line using the new capability, just as if it had
been there all the time. Nothing else is really good enough everything else leaves you with cruft growing on your code.
Refactoring is a formal process (but not a difficult one) that lets you
change the code without breaking it. Each refactoring step is reversible, so that you can try things and if you dont like the outcome, put
95
Programming
them back. This lets you have a curious, experimental, learning attitude about your code. Hmm, this seems a bit off, lets refactor it this
way. Oh, thats better, well leave it. Or, um, thats not so good, lets
put it back.
Through refactoring and focus on simple design, we can build a system
incrementally, focused on business value, without getting cornered by
an early decision that turns out to be wrong. We expect our early decisions to need updating, and through refactoring, we know just how to
do it. Read Martins book and learn refactoring. Its a critical skill in
these times of rapid change.
One more thing: one reason people dont change existing code is that
theyre afraid theyll break it. But you have all those unit tests that ran
at 100% when you started. When youre finished with a little refactoring, run them again. If they break, see what happened. Most likely, you
broke something, although sometimes youll just find that the test
needed changing to match the refactoring. The tests are your safety
net, protecting you from breaking the system during fast evolution.
Just dont tell anyone we have a safety net they wouldnt let us call it
Extreme Programming if they knew we work with a net.
Continuous Integration
Integration is a bear. We cant put it off forever. Lets do it
all the time instead.
Here's an idea. Let's divide up the system. We'll all write our share of
the objects. It should only take a few months. We'll all test our work.
Then, when everything is written, we'll just integrate the code in a
week or so, run a few acceptance tests, and release.
Does this sound like a recipe for disaster, with mismatched method signatures, objects that don't work as their users expected, and a system
that won't even load, let alone actually run? We sure hope it sounds
that bad.
96
Programming
Coding Standard
I can always read my own code. But wait, its all my own
code.
97
Programming
We all code to an agreed coding standard. This ensures that the code
communicates as clearly as possible and supports our shared responsibility for quality everywhere. It doesnt matter so much what the
standard is, as that everyone use it. Yes, we know it sounds regimented
at first, but it will pay off. Suppose someone went onto your computer
some night and reformatted all your code. Not only would you change
your password, but youd be slowed down. You might even go to the
trouble to format it all back, because you need to be able to just glance
at the code and see what its up to.
Now, it turns out that it isnt the specifics of your favorite formatting
that matter, its your familiarity with them. So push a bit for your
favorite style, but be prepared to bend and go with the teams choices.
In a very short time, if you use the new style, youll get just as good at
it as you are with your favorite. You may even come to like the other
style better. No, really, it happened to us.
Now, what about the specifics? Easy and simpler is better. If youre
programming in Smalltalk, our advice is to adopt Kent Becks Best
Practice Smalltalk Patterns as a whole. Theyre well-thought out, consistent, and simple. If youre not lucky enough to be programming in
Smalltalk, youre on your own. Look for some industry or local standards in your language, and adopt those. Here are some key topics
wed think about in our standard:
Indentation. Use a consistent indentation format. Same tab widths all
the time, same bracket placement. Always indent subordinate code,
even if youre not using Python, where you have to.
Capitalization. Use consistent capitalization practices. Follow whats
typical in your language, not something left over from another language, even if youre more familiar with it. Do they capitalize classes
and put underbars in their names. OK, go with it.
Commenting. Use sparse commenting. A focus on clear, intention-revealing code is more valuable than all the comments you can
write. Do write them when you need them - to explain an optimiza-
98
Programming
tion, to explain something you just cant simplify, and so on. Dont
write them when they dont really help.
Method size. Keep methods small. If the code cant be seen in one
display screen, its too long. Its probably too long anyway. While
youre at it, avoid those big comment blocks at the beginning of the
method - they obscure what matters, the actual code.
Names. There is another area of standardization that you want to
work on throughout the project, and thats the names themselves.
Even though your name formats will be consistent, the names of
things want to be consistent as well. Its not helpful if you call it totalSalary and I call it totPay. We need to name things similarly so that we
can find them, and so that we can understand them quickly when we
see them. The impact of consistent naming is small at first, when the
system is trivial, but as things get bigger and you learn to go faster,
consistent names do their part to keep you going at full speed. Well
worth the investment.
Use names that are intended to be read, not convenient to type.
Longer is better, within reason. The idea is that your code needs to
communicate with you, and with your colleagues, in the future, when
youve forgotten what pig and cow meant to you at the time. For
further ideas on this, read Ward Cunninghams System of Names,
http://c2.com/cgi/wiki?SystemOfNames, or the names discussion in
Hunt and Thomas Pragmatic Programmer, or go back to the classics.
In XP we call this concept Metaphor, the idea that each application
should have a conceptual integrity based on a simple metaphor that
everyone understands, explaining the essence of how the program
works. The essence of this idea is to have a common concept of what
the program is like. C3 payroll, for example, is like a manufacturing
line, building paychecks by taking hour parts and converting them to
dollar parts, assembling all the various parts until you get a paycheck.
Odd as it may seem, this metaphor let the customer and programmers
communicate clearly about what the system does and how it does it.
99
Programming
40-Hour Week
One time on your authors common project, C3, the entire team went
into a heavy-overtime mode, in order to meet some delivery date. (Yes,
even extreme teams can get up against a deadline once in a while.
Scope had not been managed properly, and we were up against it.) We
worked really hard for a few weeks. Most of the team were coming in
on weekends, in the middle of the night, and generally acting like we
were in Silicon Valley instead of Michigan.
After the crunch was over, we all took some time off and then got back
to it. We looked upon the work we had done in the overtime period,
and unlike the Creator, we did not see that it was good. In fact, it was
bad1. We found poorly written code; we found untested code; we
found unrefactored code. We found all pig iron.
1.
We offer apologies here to our wise and more gentle colleague, Don Wells,
(http://www.extremeprogramming.org), who doesnt like to call work done with the best
of will bad. Suffice it to say that we looked upon what we had wrought and did not see
that it was good.
100
Programming
During the crunch, we were honestly doing our best. Our best just
wasnt very good, because we were tired. We cant prove it yet2, but
from our own experience we are certain that heavy overtime is bad.
Thus the XP rule, 40-hour week: Do not work more than one consecutive week of overtime.
Summary
Of course programming is what its all about. XP embeds programming in a process that lets programmers stay healthy through the
course of a project, by helping the project to stay healthy. As we program, we work in pairs, using simple design plus refactoring to keep
design quality high. We integrate all the time, so that we can all
improve the code wherever it needs improving. And we communicate
through the code by writing in a meaningful, standard way.
2.
101
We cant prove it yet, but were working on it. Recent reserach has shown that the commong hospital practice of working residents and interns results in more mistakes than letting them work more normal hours. Remember that the next time you go to the hospital,
and the next time you decide to program while youre tired.
Programming
102
Sidebar - Chapter 11
Code Quality
A little more detail on something close to our hearts:
simplicity.
Remember when code is simple enough. Everything we write must:
1. Run all the tests;
2. Express every idea that we need to express;
3. Say everything once and only once;
4. Have the minimum number of classes and methods consistent with
the above.
103
Code Quality
Most classes need tests for anything that could possibly break. Writing
those tests will find problems sooner and let the project go faster. Writing the tests first will make our classes easier to use and more compact.
The code we release must run all the tests. It's not sufficient that the
tests for our code run - all the tests in the entire system must still run
whenever you release. This ensures that changes we make don't impact
other people in surprising ways.
104
Code Quality
105
Code Quality
106
Chapter 12
Pair Programming
On an Extreme Programming team, two programmers sitting together at the same machine write all production
code.
Pair programming has been around for ages. Weve heard that P. J.
Plauger wrote about working in pairs back in the 70s, perhaps in one
of his "Programming on Purpose" columns, but havent been able to
find the reference. Nearly everyone has had the experience of working
together with another programmer on something really difficult, or on
a really serious emergency, and its usually a good experience.
With pair programming, as with most of XP, we turn the dials up to
ten. We don't reserve pair programming for difficult problems, or for
serious emergencies. We do it all the time: all production code, all the
time.
Two programmers working together generate more code, and better
code, than the same two programmers working separately. They can
work longer without getting tired, and when they're finished, two people understand everything, instead of understanding just half of
everything.1
A cat is not a dog, we are told, and pair programming isn't one programmer looking over another's shoulder as she bangs in code. Pair
1.
Were not just making this up. Experiments in pair programming show its benefits. See,
for example, Laurie Williams and Robert Kesslers article in the May 2000 Communications of the ACM.
107
Pair Programming
Pair Programming
variables we've just defined. Finally, my partner acts as the pair's conscience, reminding us to keep the code communicative, to keep it
formatted to the team's standards, and to keep it tested.
Both driver and partner have responsibilities during pair programming.
The partner is responsible for being completely engaged. He's not just
along for the ride: he must understand everything that is being done.
If he doesn't, he needs to stop the process and get hooked up again.
The partner must be working the same strategy as the driver. He might
have another idea, he might even think it is better. Tough. When
you're the partner, your job is to help the driver do what the driver is
doing. Get with what's going on and support it.
The driver, in addition to typing in the code, is responsible for making
sure that the partner can be completely engaged. The driver explains
what she is doing, so the partner can understand it. She also listens to
what the partner is saying, and to what he is not saying. If she stops
hearing encouraging noises from her partner, she needs to stop and see
what's wrong. If she hears discouraging noises, she needs to stop even
sooner.
We're trying to build a mind-meld here, and both players need to keep
it going.
It takes a little time to get used to pair programming, and at first it will
feel a bit awkward. Then you'll get good at pairing with someone, then
finally you'll get good at pairing with most anyone. Just keep at it.
Here are some tips:
The partner can say Let me drive when he can't express an idea verbally, or when the driver is stuck. And it's a good idea to switch drivers
every so often anyway, just to keep from getting stale.
It's generally a good idea if the programmer who is least sure of what's
being done does most of the driving. It's easy to let yourself get sucked
109
Pair Programming
along when you don't really get it, and then you lose the advantage of
pairing.
As driver, notice all the times your partner helps. Acknowledge them
to yourself and to him. Sometimes it'll just be syntax or punctuation
help. Sometimes he'll remind you of the method name you were trying
to remember, or point to the window button you're looking for.
Sometimes he'll remind you to write a test that you need, or remind
you that the code isn't communicating as well as it could. Notice these
aids, and acknowledge them.
As partner, learn your driver's rhythm. Don't prompt every time
before he's ready. Just prompt when he's really a bit stuck. Try to
speak in we terms rather than you terms, especially when what
you have to say isn't entirely favorable. We need to make that variable
name a bit more clear.
Speak in I terms when the going gets tough. Is the driver writing
something grotesquely ugly, the least understandable code you've ever
seen? Then just say I don't understand that. Can you help me out?
Let's make it better.
Partner, don't take the driver off his strategy unless you really need to.
If you do, try something like I've got an idea. Let's try it that way for
five minutes, then I'd like to try something.
Driver, don't run away with what you're doing. Chances are, your
partner does have a better idea, because while you've been down in the
mud, he's had his head up above the ground looking around. Listen.
We can't offer much more detail than that. Each pair is unique, but the
general moves are the same. Work at pairing. The result will be more
code, better code, better understanding of the system, and more fun.
Pair programming, if you can do it, will make you go faster in any situation. In Software Development (October 1999), Larry Constantine
put it this way:
110
Pair Programming
They spell each other, check each other's work, inspire each
other, fill in each other's weak spots, and crank out better code
with fewer defects. The same formula works for learning a language or using a new piece of software - you not only learn
from the system or the material but from each other. A dynamic
duo who work well together can be worth three people working in isolation.
Pairing doesn't come naturally to everyone, but most folks get to like
it once they try it. Here are some techniques to try to get it going:
Ask for help by pairing. This is a powerful approach to many problems,
and a wonderful one for pairing, because it lets the other person be the
strong one. Jack, could you sit down and help me for a couple of
minutes? Next thing you know, you're pairing.
Provide help by pairing. When someone asks you how something
works, or how to do something, try I've got a few minutes, let's take
a look at it. Move to their machine, give them the keyboard, and help
them through it.
Send help by pairing. After folks get used to working with you,
encourage other pairs to get together: Susan, could you sit with Jim
on that and help him with those formats? I'll join you if you need me.
Drop in. Just plunk down at the desk of people who look confused.
Whatcha doin'?
Finally, remember that desk or table layout is critical for pair programming. Computer in the inside corner doesn't work. Two chairs side by
side facing the monitor, that's the ticket.
Summary
Two programmers working together are more effective than two
working alone. Team knowledge grows faster and the work is more
fun.
111
Pair Programming
112
Chapter 13
Unit Tests
Extreme Programmers test everything that could possibly
break, using automated tests that must run perfectly all the
time.
In order to deliver value as early as possible, XP teams work only on
what the customer orders. They refine the design and code continually,
so that the system is always clean and capable of evolving. Code refinement is only possible if you have lots of tests to prove that things still
work. Therefore, XP teams build automated unit tests for everything,
and make sure they run perfectly all the time.
XP teams share ownership of all classes. This lets them go fast, with no
waiting for someone else to get around to putting in a needed feature.
When code is being changed rapidly, you need to know you havent
broken anything. Therefore, XP teams build automated tests for everything, and make sure they run perfectly all the time.
Lets be clear about this: you need tests for every class for everything
that could possibly break. And all those tests must run at 100% all the
time.
Imagine that you had just been brought in to maintain an application
of a thousand or so classes, ten thousand methods, 50,000 lines of
code. The former team have all run off to join the circus. You might be
feeling some fear about now. Then your manager tells you one more
thing: Oh, by the way, there are about 10,000 tests for the system,
testing all the classes and important methods and every one of them
113
Unit Tests
runs correctly. We hope this would give you some comfort. We know
it would give us comfort.
It turns out that if its your own ten thousand methods and fifty thousand lines of code, the tests will give you the same comfort. So we
want tests for everything, and we want them to run perfectly all the
time. How do we do that?
It helps to start at the beginning. Well address later what to do when
you have a bunch of code to maintain and not enough tests. Starting
on a new project, you can have all the tests you will need by writing
them as you go. And youll go faster when you work that way, a wonderful additional benefit.
The best way to write tests for a class is to write them first test a little,
code a little rather than writing them at the end, or even writing
them all at the beginning. All of these ways will result in what you
need, but going bit by bit is best. Well focus on that.
114
Unit Tests
Well even suppose that Martha isnt done with the tax return objects,
and certainly we arent going to work with the GUI. Our mission is
just to write the Tax Return Scrutinizer.
We want to build up our tests, bit by bit. Well first test that we can
create a Scrutinizer with no elements, and that it behaves reasonably.
Our first test, therefore, just creates a Scrutinizer. Then we ask it some
questions: Give me all the returns scoring more than 10". It should
answer an empty collection. We ask it to remove all the returns scoring
less than five. It should happily accept this command, removing none
of its already-absent returns.
We create a test case in xUnit, named ScrutinizerTestCase, and write a
test that looks like this:
testEmpty
create a new Scrutinizer
select returns with score > 10
result size should be zero
remove returns with score < 5
nothing should blow up
115
Unit Tests
testAdding
create a scrutinizer
add some fake returns with various scores
see how many returns the scrutinizer has
The test for adding needs to find out how many returns are in the
Scrutinizer. We might have done that in the first test, but it wasnt on
our mind, because we knew that a new Scrutinizer has no returns. Size
seems like a reasonable thing for it to be able to answer, so well just
implement a public size method and move on. In rare cases you might
need to build a friend method or do something a little more exotic.
Generally, it can be this simple, and we recommend that you keep it
that way.
OK, now we want to test the selection. No problem, just extend the
FakeTaxReturn to have a score, and use it in a test. This would be a
good time to coordinate with Martha on the name of the method, so
shell use the same name in the real TaxReturn. Our test is easy: add a
few returns of various scores, ask for returns with scores bigger than X,
and see if we get the right number of returns.
testSelecting
create a scrutinizer
add some fake returns with various scores
select all the returns with score > 10
see if you get the right number
select all the returns with score > 5
see if you get the right number.
Unit Tests
117
Unit Tests
Unit Tests
119
Unit Tests
3. Write a test. If your new behavior will change the state of the Scrutinizer instance, code an assertion to verify its current state. Then code
sending the message for your new behavior to the Scrutinizer instance.
If you don't know the message selector, now is the time to make one
up. Depending on your implementation language, you may need to
code a stub method. Now code an assertion to verify that your
expected change in state occurred.
4. Run the test. It will probably fail. If it does not, you are done, all
that is left to do is release. Go to step 6.
5. Modify the model code and repeat steps 4 and 5 until the test runs
successfully.
6. Release the model code and the test case.
Testing questions
Now here are some questions that get asked every time we talk about
this subject, so were guessing that youll have some or all of them. If
we miss yours, drop us an email.
Unit Tests
object, perhaps one that looks at the SQL statement its sent and just
opens the corresponding data file. Other times you can test using the
data without needing to fake out the database.
But you do need to test the database access as well. Having a very few
tests that actually open the database and get records from it, making
sure that the connection works, that the records come back right, and
so on, is a really good idea. Just try to make that test as tight as
possible.
You might feel the need to test your record-mapping methods, the
ones that take the stuff that comes back from the database and turns it
into objects. These tests can be written against hard-coded data as well,
but it might be a good idea to have one that runs against the real database, just in case a version changes or something, and they start
sending you data in a different format.
The basic rule is to go to the actual database as infrequently as possible, consonant with safety, so that the tests run as rapidly as possible.
Unit Tests
122
Unit Tests
rect square roots, you could debug for a long time before noticing that
the root is wrong. Local tests give better diagnostics, so you go faster.
Unit Tests
between classes?
Our Scrutinizer problem above was an example of how a collaboration
error could show up, and discussed how to avoid it. If your system is
showing lots of such errors, theres some kind of coordination problem
happening. People are writing different responses to the same questions, or they are naming classes and methods inconsistently, or there
are consistency checks needed in the unit tests, or something. When
this kind of error shows up, its a sign that some additional work needs
to be done. All we can say is to figure out what that work is, and do it.
Since these defects are hard to find, when they start showing up, its
time to invest in cornering them.
Our own experience is that we get very few of these errors. Were
guessing here, but we think that somehow our focus on testing up
front is preventing them, but we cant prove it. And we certainly agree
that when they do show up, such problems are difficult to find. So
when they show up, we go after them vigorously, trying to build a
tighter net of tests around those areas. More than that, we dont know
how to answer.
124
Unit Tests
125
Unit Tests
126
Sidebar - Chapter 13
xUnit
Use the worlds lightest testing tool.
Starting with unit tests is a bit difficult you just dont know what to
do. Heres some free software to give you a leg up.
Kent Beck wrote a testing framework, called SUnit, for Smalltalk some
years ago. It caught on all over, especially in XP teams using Smalltalk.
He and Erich Gamma then provided the jUnit tool for Java. Today,
there are CppUnit, PerlUnit, PyUnit for Python, VBUnit for Visual
Basic, and many other languages as well. These frameworks are available on Ron Jeffries website, www.XProgramming.com. Click the
software link.
Within the limitations of the language being tested, all the frameworks
work the same way. You build a subclass of the class TestCase to
contain your tests for some object that needs testing. (And they all do.)
The test case includes as many testing methods as you want. Typically,
each one begins with test. They might be named testCreation,
testSelection, testRemoval, and such. The versions of the tool in
languages with reflection build up test suites automatically, by collecting all the methods named test.... In less advanced languages, you
have to set up the suites manually.
The testing framework collects up all the tests and executes them one
after another. Each one is initialized by calling a standard setup
method that you can override, and torn down by calling teardown.
This way you can ensure that each test runs in a clean environment, so
that mistakes in one test dont impact another.
127
xUnit
Most versions of the framework come with a little GUI that you can
use to control which tests to run, and that shows progress and your
final score. Naturally, before your code release, you run all the tests in
the system, and your final score is perfect. Click, one more notch forward on the progress dial.
Its tempting to use more complex testing tools. There are even some
out there that claim to do intelligent black box testing of your
classes. Read about these with some skepticism how could they possibly know the right and wrong answers to feed to your class. They
might build some skeleton methods, but thats not the important part.
The important part is your application of your intelligence to testing
what really needs it.
Try these xUnit tools. Theyre free, and worth ten times that much. A
hundred, maybe.
128
Chapter 14
Test-first, by Intention
Code what you want, not how to do it. Chet and Ron do a
small task test first, trying always to express intention in
the code rather than algorithm.
Warning: There is Smalltalk code in this example. We think youll do fine
and ask you to try to read along. The details of the code arent critical
the thinking and the partnering are.
Chet and I wanted to give a short demonstration to tie together all the
XP programming practices. We decided to work on an actual problem
that Id encountered at a client location. This is a transcript of an
actual session, not a sanitized session made up for the book. The
ragged edges are real life.
There are two key things to watch for in this example. First, we only
write new code when we have a test that doesnt work. We call this
test-first programming.
Second, we dont think much at all about how to do a thing, we think
about what we have to do. We call this programming by intention. You
just write code as if someone had written the hard method for you and
you just had to send the message.
The task is this: we have two collections of Sum objects. A Sum has a
name (a string) and an amount (a number). The output is to be a single collection of new Sums. If a Sum of the same name appears in each
collection, the new one should have the same name, and the total of
129
Test-first, by Intention
their amounts. If a Sum appears in only one collection, the new one
should have that amount. The order of the output should be the order
of the first collection, followed by any elements from the second that
didnt occur in the first. For example,
First
Second
Result
A1
C2
A 10
B3
A 11
C2
B3
Chet asked a few questions, mostly about whether we had any code to
start with. I said that it had been ugly and didnt work, so we decided
to start from scratch.
We were working on a new machine, so we started by defining a simple
Sum object with a name and an amount. We didnt write tests for it
because it was pretty trivial and it was just a foil in our real example.
For those who dont speak Smalltalk, well give a little commentary.
---Sum 10:25:00
The lines that look like the above just name the class were putting
code into, and the time we did it. They arent part of Smalltalk, theyre
just here to give you a sense of how long things took. Heres the class
definition:
---Sum 10:25:00
Object subclass: #Sum
instance variables: name amount
This defines a new class named Sum, with instance variables name and
amount. In Smalltalk, you dont have to define the types of the
variables.
Now we build the Constructor Method for the class. This is a method
definition. Each method definition starts with the name of the
method, tabbed out one tab stop. A method definition in Smalltalk has
a name which consists of one or more keywords. This one is
130
Test-first, by Intention
which means (self new) create a new instance of this class (Sum), then
send it the message
setName: aString amount: aNumber
which is what we call a Constructor Parameter method. The hat character (^) means answers, or returns.
We start every class definition this same way, with a Constructor and
Constructor Parameter method. It gets you going smoothly when you
always start a class the same way. Heres the whole Constructor
method:
---Sum class 10:25:00
name: aString amount: aNumber
^self new
setName: aString
amount: aNumber
131
Test-first, by Intention
OK, enough warm-up. Its time to write our object, which we have
decided to call Summarizer. We began by making a test class named
SummarizerTest. Heres the conversation we had as we pair programmed our way along.
Chet: What shall we test first?
Ron: Lets just make an empty one. That should answer an
empty collection.
Chet writes the test. He assumes that there is a method already in
existence named emptySummarizer. This keeps him focused on the
immediate task, making an empty one and making sure that its result is
empty.
132
Test-first, by Intention
133
Test-first, by Intention
defined. We expected that, but we like to run the test every chance we
get its a good habit to have.
Chet: How do we create one of these deals?
Ron: Lets define the class, give it two instance variables, call
them first and second.
Chet: I hate those names.
Ron: Me too, but I cant think of anything better.
--Summary 10:32:45
Object subclass: #Summarizer
instance variables: first second
134
Test-first, by Intention
We run the test again. This time it breaks because the Summarizer
doesnt understand summary. Chet hasnt an idea how to do the
method so he just creates one with a halt in it, then runs the test again
to get into the debugger.
--- Summarizer 10:37:18
summary
self halt
135
Test-first, by Intention
just answer a literal empty collection, but Chet was just getting his
hands on the variables a bit.
Our first test runs. Even though the object is clearly wrong, we dont
have a broken test to make us fix it. So we write another test.
Ron: Lets test the example I wrote down. (The one in the table
up above.)
Chet: OK.
Chet starts the method, creates a temp, starts an assignment to it. He
pauses and types a left paren. I know that hes about to try to construct
the test Summarizer right there.
Ron: Just send abcSummarizer.
Chet: Right.
Ron: We have to remember to tell them how important this is.
Chet: This is one of the most important things youve taught
me. I just write code that assumes that ten seconds ago someone already wrote the method I need, like the abcSummarizer
method.
Here again, were talking about intention. We just say what we want,
not how to do it. When we get there, its always easy.
--- SummarizerTest 10:39:34
testABC
| summarizer |
summarizer := self abcSummarizer.
self should: [summarizer summary size = 3]
136
Test-first, by Intention
Having built the Summarizer object, Chet is ready to enhance the test.
I wasnt ready, but he was, so I rode along as he enhanced the test to
check all the values.
--- SummarizerTest 10:43:06
testABC
| summarizer summary |
summarizer := self abcSummarizer.
summary := summarizer summary.
self should: [summary size = 3].
self should: [summary first name = 'a'].
self should: [summary first amount = 11].
self should: [(summary at: 2) name = 'c'].
self should: [(summary at: 2) amount = 2].
self should: [summary last name = 'b'].
self should: [summary last amount = 3].
Chet puts off the inevitable thinking a bit longer by declaring his
intention in the method, namely to have a collection with a and c, and
one with a and b. Again he assumes that a magic elf has already created
them. Programming his intention, not his algorithm.
137
Test-first, by Intention
Now its pretty clear what we need, since we have a name for it. So we
type in the methods:
--- SummarizerTest 10:45:45
acCollection
^OrderedCollection
with: (Sum
name: 'a'
amount: 1)
with: (Sum
name: 'c'
amount: 2)
--- SummarizerTest 10:45:59
abCollection
^OrderedCollection
with: (Sum
name: 'a'
amount: 10)
with: (Sum
name: 'b'
amount: 3)
138
Test-first, by Intention
Ron: Good, I like that. So well just process first, then process
second.
--- Summarizer 10:50:29
summary
self
processFirst;
processSecond
139
Test-first, by Intention
Chet codes just what we said. Our intention is find matching Sum, add
our input Sum into it. The code says just that. Now we run the test
and, of course, matchingSum isnt defined.
Ron: We have to go through the existing summary items and
see if we have a matching one ...
Chet: detect!
Ron: Yes, do a detect ...
Chet: and ifAbsent:
Ron: ifNone:
Chet: I never can remember which it is.
Ron: Make a new Sum and put it in the summary.
Chet codes it up. This is a pretty standard Smalltalk idiom, so he codes
the whole thing in line. The code just says that itll find a Sum in the
summary with matching name if there is one, and if not itll create a
new one of that name, and put it in. In either case, it gives back the
new or existing matching Sum. You could make a case that we should
140
Test-first, by Intention
have broken it up, but we discussed it and couldnt find a way we liked
better.
--- Summarizer 10:56:40
matchingSum: aSum
^summary
detect: [:each | each name = aSum name]
ifNone: [summary add: (Sum
name: aSum name
amount: 0)]
We run the test. It doesnt run because Sum doesnt understand how
to add. We quickly build that:
--- Sum 10:58:40
add: aSum
amount := amount + aSum amount
We add the final line to summary, then run the test. It runs. We celebrate briefly, wishing we had a bell to ring. Then we begin to review
the code now that it works, to see if we should clean it up.
Chet: process: isnt a very good name.
Ron: We could say summarize:.
141
Test-first, by Intention
Chet: OK.
--- Summarizer 11:04:45
summary
self summarize: first.
self summarize: second.
^summary
Chet runs the test and it works. But he doesnt like the new method
the way it is.
Chet: Oops, better change processItem: to summarizeItem:
while were at it.
Ron: Good.
He changes summarize: to send summarizeItem:.
--- Summarizer 11:05:30
summarize: aCollection
aCollection do: [:each | self summarizeItem: each]
The test runs again. At this point we look at what we have done and
find it good. We stop, and go to lunch at Red Hot and Blue. We each
have a Pulled Pig sandwich.
Review Remarks
142
Test-first, by Intention
Summary
Experiment with writing little tests first, and with always expressing
your intention, not algorithm, in the code you write. We think youll
find that the work goes more smoothly, and you wind up with code
that communicates what you mean to do, not just how you did it.
143
Test-first, by Intention
144
Chapter 15
Releasing Changes
Using collective code ownership and comprehensive unit
tests, an XP team releases changes rapidly and reliably.
An XP team practices collective code ownership: every class and
method belongs to the team, and any team member can improve anything that needs it. Collective code ownership lets the team make faster
progress, because no one has to wait until someone else gets around to
fixing something. And the code stays cleaner, because programmers
aren't forced to work around a deficiency in one object by hacking up
another.
One of the most important parts of making collective code ownership
work is the process of releasing changes to other programmers on the
team. This chapter wont tell you everything you need to know about
code management, just give you some ideas about how to interact with
your code manager.
When a XP programming pair is working, their code goes through
three phases. These phases are:
1. Local. This is the first phase of development. The pair has just started working, and their changes are not available to any of the other
developers.
2. Release Candidate. The programmers have finished their task, and
are ready to begin the process of releasing their changes to the oth-
145
Releasing Changes
er programmers.
3. Released. This is the current official version of the code. This code
is guaranteed to work, i.e. all of the Unit Tests run at 100%. Released changes are available to all of the other programmers.
Throughout the day, an XP programming pair would probably release
changes at least once, and potentially many more times. Meanwhile,
other pairs have also been making changes and releasing them, and
theres a chance they will have changed the same things you did. Youll
need an approach to releasing your changes that keeps things running
smoothly.
The process we recommend goes like this:
1. Always start with all of the released code. This ensures that you are
starting with the latest and best versions of everything.
2. Write tests that correspond to your task. (Write the test first)
3. Run all the Unit Tests.
4. Fix any Unit Tests that are broken. Since you started with the released code, the only tests that should break are the ones you just
wrote. It is your responsibility to fix them.
5. When all of the Unit Tests run at 100%, your local changes become
release candidates.
6. Release Candidate changes are integrated with the currently-released code. We recommend the use of a separate integration machine for this, and well describe it that way. Go to the integration
machine. Load all the released code. Load all of your Release Candidate changes. Then check for conflicting edits. The currently released code should be the same code you started from. If it isnt,
another pair has released before you. This doesnt happen often,
but lets assume that it has.
7. If the released code was modified while you were making your
changes, compare the differences between your changes and the re146
Releasing Changes
leased code. Use a diff tool if possible, not just your eyes. Identify
the changes released by the other pair(s), and integrate those
changes with your changes. Ask the other pair for help if you need
it.
8. Once you have integrated any necessary changes, run the Unit
Tests on the integration machine. They should run to 100%, and
they usually will. If they dont, it usually means you missed integrating something, or that your changes and someone elses conflict.
The Unit Tests that fail will pinpoint the problem. Fix all the problems. Again, get help from the other pairs if you need it.
9. When the Unit Tests run at 100%, release all of your code - that is,
make the code on the integration machine the official version.
The release process generally goes more quickly than it took to write
about it. A few minutes to load your Release Candidates on the integration machine, a quick check for conflicting edits, ten minutes to run
the Unit Tests, and then the code can be marked as released.
If you're using VA Smalltalk, VW Smalltalk, or VA Java, we recommend using ENVY. There are alternatives, but ENVY is the preferred
choice in our opinion.
In other environments, or if you just can't swing the price, a tool like
Visual SourceSafe, PVCS, MKS, or TLIB will do the job. There are
147
Releasing Changes
Troubleshooting
lots of code managment tools out there - read this chapter, then check
them out and pick one.
In general, set as few restrictions as possible into the code management
tool. No passwords, no group restrictions, as little ownership hassle as
possible. Your objective is for everyone to own everything. Everyone
has equal rights to all code.
Begin your project with no segmentation into code groups or topics.
It's best to use a flat structure as long as possible. Let the flow of code
development tell you what organization is needed, when the time
comes. Then refactor the code database.
Troubleshooting
The two most common problems with releasing changes are lots of
conflicting edits, i.e. taking too much time to merge changes, and lost
changes.
148
Troubleshooting
Releasing Changes
In rare cases, you may need a more formal check out / check in process for a few classes. Avoid this if you can, but be alert for the need to
do it if too much time is spent merging changes.
Also be aware that different classes will become hot. It might be a
good idea to sign up for tasks with hot classes in mind, so that fewer
pairs will be likely to need the same classes.
Lost Changes
Losing changes are a time wasting nuisance. The main cause of lost
changes is incorrectly merging release candidate changes with released
code. This is usually either because a conflicting edit was not recognized, or the programmer incorrectly merged the two sets of changes.
The solution to this problem has three parts. The first two parts of the
solution are: always start with all of the released code, and always
release changes frequently. Frequent releases minimize the chance that
the released code has changed. When changes do have to be merged,
frequent releases minimize the impact. Remember Continuous Integration, page 96.
The third part of the solution is your Unit Tests (page 113). Code
can't stay lost for long if there's a test somewhere relying on it. Be sure
you add tests whenever you add code to any class. Since all the Unit
Tests must all run at 100% before any code is released, this ensures that
other programmers cant break your code by accident.
Another common cause of lost changes is intentional reversion. Sometimes you want to roll a class back to a previously released version.
When this is done, you will of course lose all the changes relating to
that path. Unfortunately, you will also lose valid changes that were
done along the way. The solution for this type of lost change is to go
forward, not back. Start with the currently released code, and identify
the differences between it and the desired version. Then edit the currently released code to bring it back into line with the previously
released version, but retaining any new code. These changes are release
149
Releasing Changes
Troubleshooting
candidates, and when the Unit Tests all run at 100%, the code can be
released.
Finally, give detailed consideration to preserving your source code. An
XP project is like any other in this regard: you can be sure you'll lose
the source manager files as soon as they aren't backed up. So use normal precautions in setting up procedures for use of the tool you
choose.
Conclusion
Code management and your release process is right when it is unobtrusive. It should be easy and fast to get the source you need. It should
be easy and fast to save your changes. The code manager should detect
conflicts, and resolving them should be straightforward. There should
be no waiting if a pair needs to edit something, they should feel free
to go ahead.
A good Extreme pair saves code very frequently, multiple times per
day. If the code manager is making you want to release less often, fix
the code manager. Rapid progress depends on rapid and frequent
release.
150
Chapter 16
Do or Do Not
Weve now covered most of the programming aspects of XP.
Heres a summary of things we do and things we dont.
Extreme Programming is about doing. For each key aspect of software
development, XP prescribes a few simple practices aimed at helping
you know when you are done, and know when you are right.
But XP is also about not doing. Over the years, software development
methodology has become encrusted with practices that, for most
projects, do not advance the actual effort of producing the product
that is wanted: the software.
The result of an XP project is a computer program. Not just any computer
program,
but
a
well-crafted,
flexibly-structured,
properly-documented computer program, shown by testing to meet
known and documented requirements.
Remember that: if you're doing XP right, at the end of the project you
will have a computer program that is
well designed;
well crafted;
flexibly structured;
properly documented;
tested;
meeting known and documented requirements .
151
Do or Do Not
Some of the things that we do not recommend doing are a bit controversial. As you review the simple XP processes, we're sure you'll see
that the other things aren't always necessary after all.
Here are a few examples of things we do not recommend:
Don't try to design the whole system before you start implementing. Usually, requirements changes alone will make this impossible.
In any case, no existing design methodology is effective enough to
avoid problems during implementation, and a process of design a
little, build a little will allow you to learn faster and get a quality system done sooner.
Do design all the time. Begin simply, and as you learn what the design should be, refactor to make it so. Never stop designing, never
stop making the code agree with what the design should be.
Don't try to freeze requirements before you start implementing.
Requirements changes show that the customer is learning! Sure, it
would be nice if they knew just what they wanted before you started
building things, but the fact is that when they see what you're
building, they'll learn what they meant. XP lets you use a development and planning approach that allows for change, without big
up-front investment in frameworks or flexibility.
Do develop comfort with taking on any story in any order. Sure,
sometimes order makes a difference, but more often than we programmers think, it doesnt. Just tell the customers the cost of every
story, and let them choose.
Don't produce voluminous design documents at the beginning.
Don't even produce them in the middle: produce them at the end.
Extreme Programming teaches you how to keep the design flexible,
for highest flexibility and fastest implementation. The design documents you produce at the beginning will go out of date very
quickly (they always do, even on non-Extreme projects), and you'll
either waste time updating the docs or let them get out of date. Either is bad.
Do focus on communication. A few diagrams can help. A big picture on the wall can help. More important, however, are clear code
and talking, talking, talking.
Don't produce documents or other artifacts that aren't being used.
152
Do or Do Not
153
Do or Do Not
154
Chapter 17
Experience improves
estimates
Each iteration we gain experience. Experience with stories
helps us estimate future stories more easily and more accurately.
Youve just released your changes for some task. When you finish all
the tasks in a story, its time to take a moment. For example, when
Chet and I wrote the Summarizer program in Test-first, by Intention
(page 129), it took us about an hour. From now on, well have a good
idea of how long it takes to do tasks that are about that hard. And of
course its not difficult to estimate whether a given task is about the
same size as the Summarizer, or half as big or twice as big.
This means that when we have a task like that one, we can estimate
about how long it will take and be pretty reliable. And the more we
estimate, and the more we pay attention to how things really turn out,
the better well do.
Some tasks, of course, arent anything at all like the Summarizer.
Thats fine, you have lots of tasks and lots of time. As you do your first
few tasks interfacing with the database, note how long they take. As
you write the first couple of reports, note how long they take. And so
on.
You can read more about task creation in Team brainstorms Engineering Tasks (page 81), and in How to estimate anything (page 217), but
155
the simple answer is that when the team has a big thing to do, they
brainstorm how to break it down, until it is broken into small enough
tasks that experience allows them to estimate.
The important things to remember about XP task estimation are just
these:
1. Estimate each task that you sign up for. Dont try to get down to
minutes its probably best in a project not to go below half a day.
For the Summarizer, I estimated two hours, but it only took one.
My partner was great.
2. Estimate the amount of actual time you will spend working, with a
partner, at the machine, on the task. Dont worry about time youll
spend discussing it, drawing pictures, or thinking. These things will
all average out when you measure your velocity. The important
thing is the size of the solution, in time spent implementing.
3. Pay attention to the actual time you spend working, at the machine,
on the task. You can write it on a card if you want to, but since
youll probably want to focus on just one task at a time, memory
will probably suffice.
4. Take a moment. You estimated a day. It took a day and a half. Or
you estimated a day and it only took a half. What was it that you
missed in the estimate that would help you estimate better next
time?
It should be pretty clear that if you do this a lot, youll get really good
at estimating how long things will take. Feeding this knowledge back
into each Iteration Plan makes things go more and more smoothly and
easily.
156
Chapter 18
Resources
Keep track of key resources: planned vs actual: number of developers;
number of customers assigned to the project; number of testers; number of computers in development, test, production; and so on.
Scope
157
Keep track of the number of stories over time: how many exist; how
many are done; how many more are expected. Consider tracking total
estimated time for the project and estimated vs actual scope
consumption.
Quality
Use a standard acceptance testing graph showing number of tests and
number succeeding over time.
Time
Track the results of each release plan. Graph schedule vs time. Discuss
dropped or added functionality and its impact on time.
158
Each iteration, graph how many story cards exist and how many are
done, on a bar chart. Color completed cards green and those still to be
done white. (Not red - red means bad.)
Completed Stories
160
140
# Stories
120
100
80
60
40
20
0
1
Iteration
Completed
Stories
Take a look at this graph. What is it telling us? The growing portion of
green shows that we're making good progress. But we seem to be getting more stories as well. What's up with that?
It's your project, so you'd better know. Here are some possibilities:
Stories are being split for better planning. (release plan). In this case
the work isn't really increasing, and everything is probably OK.
Consider adjusting the historical columns to show the new story
count also.
Stories are being added because progress is good. This can actually
happen, and if you can make the original date, might be OK. Con159
160
OK, the first and most important quality graph is unit test scores over
time. Here is it. Copy it out of the book and post it on the wall.
Score
80%
60%
40%
20%
0%
1
10
Iteration
That's right. You must have unit tests for everything that could possibly break, and they must always be at 100%, for every release of code
by every programmer. That's one graph done.
The official public XP measure of quality is, of course, your acceptance
tests. What are the most important dimensions of acceptance tests?
The number of acceptance tests gives a good measure of the scope of
your testing. And the number of tests succeeding tells you how well
you're doing.
What should the graph of number of acceptance tests look like? As you
get close to release, it should flatten out, as you think of fewer and
161
fewer things that still need testing. It will probably start slowly and
ramp up, giving a classic s-curve.
10
Month
Correct
Tests
The success curve will generally be lower than the number of tests. Yes,
if your code is perfect and never breaks, they'll be equal. If you can
really do that, go for it, and write and tell us how. For the rest of us,
we'll color under the graph, green for success, red for failure. Put the
green on the bottom, it shows progress better.
162
Graph the scores at the end of every iteration, for a graph like the one
above. Within the team, youll want to graph the scores more frequently, preferably every day, for something like this:
# Tests
200
150
100
50
0
1
10
Month
Correct
Tests
For your monthly report, these graphs will probably suffice to show
progress toward quality at completion. Internally, however, you may
want more.
Usually your acceptance tests will break out into some natural organization. Each of these breakouts will probably have several, perhaps
163
many individual tests in it. If you want to see how errors are clumping
by product area, produce a graph showing success/failure by area.
rates
payments
Correct
insurance
Tests
164
The point of this graph is to identify, daily, things that are improving
or breaking. Compare this chart with the previous one:
rates
payments
Correct
insurance
Tests
165
10
11
Date
Take a look at that big dip. A bunch of tests broke that day. The next
day a few came back, and over the next couple of days, it looks like
they all came back. You can tell a lot about what's going on in the system from a simple chart like this.
Set up your acceptance testing process to produce a few numbers each
day, and enter them into Excel or your favorite spreadsheet. Run the
graphs and put them on the wall. Talk about them at the daily
stand-up meeting. Your tester should bring up the test topic every day,
even if nothing changed: Running acceptance tests. Numbers 3701
and 4130 are still bad. A couple of others broke but Susan says she
knows what happened and they'll be fixed by tonight.
166
10
9
8
T
e
s
t
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Date
167
per class, all kept historically of course. Source lines, story completion
rate, tasks per story. Pair programming time vs reported defect rate.
There are lots of great metrics. Color charts, rates of change. Fantastic,
and with a few scripts, a little Perl, some Excel, you could know so
much.
Stop! Cut it out! Dont do that!
The success of your project is in Resources, Scope, Quality, Time.
Track these, as shown here, and you'll know more than most projects
ever do.
The success of your project is in your people. Watch these few variables, and if they show there's trouble, talk to the people. Watch the
people. Are people relaxed, friendly, playing around, throwing Nerf
balls at each other? Good. Are they heads down, avoiding eye contact,
snapping at each other? Not good.
Watch the people. You can spot trouble coming, and avert it, long
before it will ever show up in your metrics.
168
Here are some things I've been asked, or asked myself, that I sometimes wish I had written down.
Number of classes and methods by date;
Number of test classes, methods, and shoulds by date;
Number of stories available by date;
Number of stories replaced, destroyed, split by date;
Risks identified;
Daily journal of feelings and observations;
Significant events or comments made by people.
But heres the telling thing: while a number of these would be interesting in papers about the projects, or in conversations at conferences,
not one of them would have helped the project succeed even a little bit
better. Sure, we can see how they might have helped. But the chances
of their helping are awfully small. Theyre not worth taking time away
from actually helping.
Your best friend is the facts, even if they aren't in your favor. But if you
track them, the facts probably will be in your favor! At the end of the
project, you may want to have a retrospective, to help the organization
learn. When you do, it can be difficult to reconstruct certain bits of
history.
What was the project velocity in terms of stories per time? Alternatively, what was the load factor, and how has it changed?
What was the schedule and number of completed points you predicted at each release plan?
How did the acceptance test scores change over time?
How rapidly did the code turn over? Did you get more or less reuse within the system than you expected?
169
170
Chapter 19
Steering
The estimates are wrong. Your priorities will change. You
must steer.
Youre smart people, and youre going to be learning during the
course of your project. Customers will learn what they want by seeing
what they get, and by learning the cost of the features they would like
to have. The programmers will learn that some things are harder than
they thought, and some things are easier. They will learn good ways of
doing work that they need to do a lot of, and theyll build tools to
make things go faster.
The results of this are clear. Im sure your own history will agree when
you look back on it: on most projects, the estimates are often wrong,
far too high or far too low, and the priorities will change before you
even begin, let alone before you get to the end.
XPs practices help with the estimates. Many of the estimates youve
heard about, where projects took far longer than they were supposed to, were based on demands, not on measured performance and
estimates of difficulty. So the estimates of an XP team tend to be quite
good. However, there will still be variability. You will inevitably find,
over the course of the project, that a large number of stories get easier
and easier to do. Most teams find that there are stories where the first
couple take a few days each, and the remaining similar ones can be
done at ten per day.
171
Steering
Most teams also find that there are some stories that take much longer
than originally estimated. Its easy to be upset by this, or to look for
someone to blame. (Look no further: Its Chets Fault, page 223.)
Software is difficult. Specifying software is difficult, and designing it is
difficult. Theres no need to make it more difficult, so lets not.
Instead, lets just assess our situation and steer the project on to
success.
When things take longer than they should, take that result into
account in your planning. Fact is, well make it up later rarely happens, and its not the way to bet. If you are the fortunately project that
hits the Making It Up Later lottery, dont worry, youll have plenty of
ideas about what to do with the extra time. Consider selling it to all
the projects that dont hit the lottery. Or use it to put additional value
into your project.
But plan to proceed at the pace youre measuring. If certain stories are
going slowly, look for similar ones and assume that they will go slowly
as well. Get the team to reestimate those stories, or, for that matter, all
stories. Use that information to decide which stories to do first, and
which to defer. If it looks like some important story that you were putting off wont get done, move it forward, at the expense of things that
dont look so important now.
Steering your project will give you great pleasure and great success. As
you learn what you need, an XP team can adapt to those needs. As you
learn how long things take, you can rearrange stories and split stories
to build an excellent product. Frankly, we believe that the process of
selecting and steering will deliver a better product than getting everything you originally imagine youll want. And the most important
thing is, steering to success is actually possible.
172
Chapter 20
Improve estimates
Story delivery is important, but its not the only thing. Since we base
all our planning on estimated difficulty, we need to get feedback on
difficulty. When we planned the iteration, we broke each story into
173
tasks, and the programmer who signed up estimated each task. During
the iteration, we need to reflect on these estimates.
First of all, if an estimate is turning out to be seriously wrong, it could
jeopardize finishing the story, so we want to check up on how were
doing against estimates frequently enough to let us reallocate resources
to get things done. Second, reflecting on how long tasks take will help
you estimate better next time.
Experience in task estimation, with feedback, will improve programmers' ability to estimate. This will feed back into the estimation of
stories that you do during the Release plan. With improved estimation
at the story level, you'll have improved information about what you
can accomplish, and when. This increases the chance of project success.
Tracking
If the main point of the iteration is to get stories done, then the main
purpose of steering the iteration is to make that happen. All during the
iteration, we want to steer so as to make sure that as many stories as
possible get completed. To accomplish that, we need to track the tasks.
Sometimes we call the person with this responsibility the Tracker.
The team needs to check, every few days, how all the tasks are going.
You can do this by having Tracker go around to all the programers
every few days, or by covering task progress at the morning stand-up.
Going around is better if you can find someone who can do it without
driving everyone mad, do you hear me, mad.
Sometimes a programmer will go off track. She may make the wrong
choice at some decision point, or make a poor choice of where to
begin. Often programmers feel that they are just about to solve the
problem - they can be just about to crack it for days at a time. Tracking is an independent check of how things are going. The tracking
function identifies tasks that are going beyond their estimates and gives
the team a chance to deal with them. More tasks get completed this
way, and the team is more successful and confident.
174
All you need to do tracking is the contents of the Iteration Plan: the
stories chosen, the tasks to be done, who signed up, and what their
estimate was. Oh, and you need the programmers, so you can talk to
them.
You need a pencil or pen, and some cards or a clipboard or a spiral
notebook. Some people record tracking results in a spreadsheet, and
there are coming to be tracking products. But the essence of tracking is
the face to face contact, and a couple of numbers per task. Paper works
fine.
It's tempting to just have the programmers email in their results every
couple of days. Forget it. XP is about people, not computers. The eye
contact is important. The team-building human contact is important.
Well pretend youre using cards. If youre not, make suitable adjustments to what we say here. Write each programmer's name at the top
of a card. On the card, write each task she signed up for, plus her initial
estimate. Leave a little space between tasks. But don't worry, you can
make a new card if you mess this one up.
Talk to each programmer thus:
Hi Dave, I'm here to track. You signed up for task XYZ. How much
time have you worked on it so far?
Dave replies, About a day.
Then ask, How much do you think you have to go?
About one more day.
You initially estimated two days. So it's going about as you thought?
Yes, it's going fine.
Dave, you also signed up for ABC. How much time on that so far?
175
Well, I've got two days in on that, and I think maybe about a day to
go.
Your ears prick up. (If you can actually do this, you are a born tracker.)
You originally estimated a day and a half. What happened?
Well, it's taking longer than I thought.
From Daves vagueness, you get that the ABC task is in trouble. You
may ask more questions, or might suggest a CRC session, or might ask
the coach to drop in on Dave and his partner. It's not Dave's fault:
these things happen. The thing to do is to make sure that it gets sorted
out.
There are several actions to initiate when you discover that the iteration is off track.
First of all, bring the information to the team level. A story not getting
done is not an individuals problem, it is the teams problem. The
sooner you get to solving it, the better youll perform. See Its Chets
Fault on page 223, for one way of dealing with the blame aspect.
Coach Dave to bring it up himself, and offer to handle it for him.
Dont let it slide.
Second, solve the story problem within the programming team, if possible. Often other people are ahead of schedule or can buckle down a
little bit to pick up the slack to complete all stories. If this can be done,
it should be done. The programmers should have it be a point of
honor that the team makes commitments whenever possible.
Third, give some special attention to the particular task thats off track.
Call a Quick Design Session (page 87) in almost every case, to make
sure the best minds are looking at what has turned out to be a problem
task. Consider giving the task owner a new partner, or even switching
owners. Sometimes youre just down a rathole on a task and a new pair
will do better. Yes, we know that will feel like a defeat, but move to
another task and play that one to win. The iteration is the important
thing.
176
Fourth, if the team just cant pick up the slack, get the customer
involved. Level with them on whats happening, and ask them to make
the call on what to do. Sometimes theyll have you drop a story and
often its a different one from what you expect. Sometimes theyll simplify a story, so that all stories can be completed, but one is a bit
smaller than first planned. In any case, its the customers call. Strange
as it may seem, youll engender more confidence by getting them
involved as soon as theres trouble. And confidence is what will get you
a successful release.
Benefits of Tracking
We do recommend that teams have a Tracker. However, every team
weve worked with has had trouble getting someone to fit the position.
The tracker needs to have a non-threatening approach to getting information, needs to be sensitive to body language and other non-verbal
behavior, and needs to be willing and able to track on a regular basis.
Weve tried it with peers, customers, managers, and people who happened by on the street. Our best experience was with a manager who
was really good at being non-judgmental, but whose slightly sad
expression when people fell short encouraged people to do their best
for him. Our worst experience was when we tried switching to a different tracker each iteration, making it a rotating duty among the
programmers. The individual variability in personality and style just
didnt help.
A close second in undesirability, by the way, is using the customer for
tracking. Its difficult for the customer to be non-judgmental, as they
are rightly so involved in getting the most done that they can. And
they are prone to solve the problem on the spot instead of letting the
team solve those that they can.
Tracking is a critical activity, giving you the best chance of recovering
from stumbles within the iteration, helping with the ongoing communication in the team, and adding confidence. It helps you be sure that
you deliver complete stories rather than stories that are nearly done.
177
It helps programmers focus for a few moments every now and then on
their estimates, improving your ability to know whats going to happen. And it puts a little attention on the task brainstorming process, by
finding those cases where the task list wasnt complete, and helping the
team learn from the mistake.
You can track with a Tracker, if you can find one. You can track during
your daily stand-up meetings. There are probably other ways, as well.
One way or another, track the iteration as it goes along. Steering is
best if you do it all the time.
178
Chapter 21
179
180
Summary
Steering the release is the most critical aspect of XP. No matter how
fast or slow the team is, no matter what happens as you go along, your
best shot at a successful release by your scheduled date is to steer. Fortunately, steering is easy. Know whats done, know how fast your team
is moving, and use that knowledge to decide what to do next, and
what to defer.
1.
181
PERT and project software often do more harm than good. They give you the illusion of
truth when all you have is estimates. They give you the illusion of control when all you
have is data. They focus your attention on your computer screen instead of your people.
For an XP-sized project: Resources, Scope, Quality, Time (page 157) thats all you
need. Do we repeat ourselves? Then we repeat ourselves.
182
Chapter 22
Handling Defects
Report em, schedule em, test and fix em, avoid em. Just
dont call em bugs.
Call them Incident Reports, Customer Information Requests if you
like. Just dont call them bugs. Bugs are things that creep into your
software against your will. Every defect in your code was put there by
one of the programmers. Two of the programmers, with pair programming. With the customers we visit, when something goes wrong, they
think its a defect. Well talk here about reporting the problem, scheduling the repair, testing and fixing the problem, and avoiding as many
defects as possible. But first, a word from our sponsor.
Defects reduce the value of the software to the customer. That runs
counter to our primary purpose, delivering value to the customer.
Defects also get in the way of delivering future value, by taking time
that could have been used to do new things. Finally, defects that get
through to the customer slow us down disproportionately. Since we
dont have a test that shows the defect, it is often harder and more
time-consuming to fix.
OK. We dont want defects. Hold that thought while we deal with
them.
Reporting Problems
The users are on line and perhaps in their own space, away from you.
They may want an easy way to submit problem reports. If they want to
183
Handling Defects
use email, thats OK. If they ask you to build a problem reporting tool
right into the software, thats OK too. The question is what do you do
with those emails when you get them.
Write them on cards. Thats right. You already have a good scheduling
mechanism. Why not use it?1 Lets go on to ...
Scheduling Corrections
If the problem is of low enough priority, the customer can just write it
on a card (or someone can), and schedule the fix in a future iteration.
This is by far the best thing to do, as it uses your normal practiced flow
of planning. Where possible, write them on cards and schedule them
like any other story.
More urgent problems are a bit more complex. They need to be
addressed in the current iteration, typically right away. Often, that
means that some already scheduled work wont get completed. What
should be deferred? That, of course, is up to the customer. Youll need
to communicate proactively on this, because you wont even know
how long it will take to fix until youre nearly done. If youre dealing
with a flow of defects, be sure you know your story and task priorities,
and be sure you keep the customer up to date on the impact of your
bug hunting. Consider putting a maximum amount of time on hunting before you consult the customer. They might want to reduce the
priority of the defect if its going to take a long time.
Keep track of the time spent fixing defects. Graph it on the wall. Its a
potentially important consumption of resources, and well worth
watching. When you get some history on your velocity in the presence
of defect fixes, use that velocity figure in planning the next iteration. As
always, past history is your best indicator of future performance. But
keep the defect time broken out and displayed. It may be taking a big
bite of your development time, and if it is, you want to know it and do
something about it.
1.
Some folks want to have a defect database. We call that a defeatist attitude. On a greenfield project you may well be able to do without. Give it a try!
184
Handling Defects
When the flow of support issues is high enough, some XP teams dedicate programmers to support and fixes, usually on some kind of rolling
schedule. Feel free to try this, as it has the advantage of letting the bulk
of the programmers focus on new value without interruptions. There is
an important downside to this approach, however: it reduces feedback
in your process. By masking the impact of problems, you lose quite a
bit of the incentive to avoid them. Some teams like to have defects
sting a bit as they come in, to help remind them not to send them out.
Preventing Defects
Lets face it, the fewer problems we have, the better were going to like
it. Its not realistic to expect no problems, but its not healthy to get
complacent. Sure, there are bugs in almost all software. So lets not get
too excited when there are bugs in ours. Maybe were afraid that if
bugs arent inevitable, bugs in our code will mean we arent as good as
we should be. Well, weve all worked hard to get where we are, so we
probably are as good as we should be. But unless weve stopped learning, we arent as good as we could be. We arent as good as we can be.
185
Handling Defects
Summary
Thats the scoop on defects. Report them, schedule them, test to fix
them, prevent them. Go now, and bug no more!
186
Sidebar - Chapter 22
Advanced Issue:
Bug Databases
After release, if you have multiple users reporting problems, you clearly
need some mechanism to keep track of them. If you have lots of users,
writing on a card may not do. In December 1999, Ron was involved in
a newsgroup conversation. Here, he is addressing whether a bug database is needed during active, pre-release, full XP development.
Ken asked:
Bug tracking will allow you to uncover 'smells' in code (to use a
refactoring phrase). If there are a large number of problems in a
particular segment of your project then you may want to really
focus on that segment and stabilize it. How do you identify this
clustering unless you keep track of the errors. For example: we have
50% of our errors relating to monthly payroll.
Yes, the potential problem is real. If there are a large number of problems in some area (even over time), then that area needs focus. Ken
asks a good question: how do you keep track of this clustering?
Suppose some class, BadClass, hasn't been well-tested and is poorly
written. It's a bug cluster. It can and does happen.
How are the defects that cluster in BadClass detected and found? Or,
rephrasing the question slightly, and I hope harmlessly, how do the
existing XP practices naturally identify and deal with bug clusters?
187
Susie and Bill, using BadClass as they build more function, encounter
those defects, which show up when their Unit Tests stop working
because of a problem in BadClass.
XP has Collective Code Ownership. So Susie and Bill fix BadClass. To
do this, they need to have a Unit Test for BadClass that is failing.
All its tests work now, so they write one that shows the defect. They fix
the defect.
Similarly, an Acceptance Test may show the problem. Someone has
that story and needs to make it run. They find that BadClass is failing.
Again they write a Unit Test and fix BadClass.
Fixing BadClass, Susie and Bill notice that the code is ugly. They may
refactor it a little, or might make a note to do it later.
At the next stand-up meeting (no more than 24 hours away) they
report what they're doing. Because they're a little ticked off about
BadClass biting them, they mention it. Everyone gets a little nudge
that BadClass is in fact bad.
BadClass is a bug cluster, so others have been bitten by BadClass, and
they join in the grousing.
Soon, a couple of people will say BadClass has been ticking us off
long enough, let's go after it, and they'll do just that.
So the normal effect of Relentless Testing and Collective Code Ownership and Daily Stand-up Meeting is that the defects in BadClass get
found early and often, and the whole team gets an awareness of where
the bugs are.
That's how the XP practices naturally identify and deal with bug
clusters.
During the active implementation of the system, then, the whole team
tends to know what's bad, and the bad tends to heal.
188
Might this be enough to ensure that there will in fact be no bug clusters? Well, it could happen. In my experience, it DOES happen. The
team knows where the system is weak and they go after the weak places
as a natural part of their work.
My original short answer was based on the above characterization of
how the existing XP rules and practices automatically attack and
eliminate bug clusters. I didn't make that clear.
So I question, based on experience with bug databases and with XP
whether, during pre-release development, a bug database would carry
its weight.
But Ken goes on:
Process improvement is about feeding the loop. XP starts this by
including Unit tests when bugs are discovered.
Yes. And the XP value of Simplicity suggests that a team might well
start with the core practices and improve their practices where they
need it, rather than assume they will need it and add weight to the process from the beginning. That's where I'm coming from. Id strive to
keep the defect count low enough to avoid the slower feedback from
the database. But when I needed the database, Id get one.
There are other elements that could be picked up from the other
camps.
Unquestionably. The trick in XP, because you want to go fast, is to add
only process elements that are actually needed, that will deliver more
benefit than they cost.
During development, before there are multiple streams of support
requests, I sincerely question whether a bug database would be
needed. I know of lots of successful XP projects that don't have them.
189
190
Sidebar - Chapter 22
Advanced Practice:
Tests as Database
Heres a tip from Chet on keeping track of defects by using process
elements you already have: your tests. Stop relying on a trail of paper
or emails, or even a database, to keep track of bugs. Instead, write tests
to show bugs. You will need to decide how you will implement a
test-driven bug list. Since the unit tests must be kept at 100%, you
must decide how to have tests that document current bugs. There are
several ways to do this.
1. Define bug tests as acceptance tests (which may be below 100%).
2. Keep the bug tests in a separate unit test category and shift them
into the production unit suite as they are worked on.
3. Defer writing the test until you are ready to begin working on the
bug. This can mean that the test will never get written, which isnt
a good thing.
4. Or the most fiendish way, take the failing test and release it into the
production test suite and let it lay in wait for the next team of programmers to come along with code to release. They will discover
the failure while running the production release suite and be forced
to fix it before legally releasing their code. Moo ha ha ha ...
When the team responsible for capturing bugs finds one, they do
enough analysis to be able to reproduce it in a test. The test is then
passed along to the team responsible for fixing the bug. The correction
team now have a concrete example of the failure and are able to work
in the standard 'write the test first' mode.
191
Youre doing this right when bugs are corrected quickly, without
excessive meetings and confusion about what the bug report meant.
192
Sidebar - Chapter 22
193
Youre doing this right when defects are corrected quickly, without
excessive meetings and confusion about what the defect report meant.
194
Chapter 23
Conclusion
We have been working with Extreme Programming for over four years,
and would never go back to what we did before. XP has equipped us to
communicate better with our peers, our customers, and our managers.
It has helped us to manage the stresses of working hard on something
we deeply care about. We think its good stuff and we recommend it to
anyone working on a project of suitable size and scope.
The values of XP are simplicity, communication, feedback, and courage. Theres certainly enough to XP to fill this book and several others,
yet the essence truly is simple. Be together with your customer and
your fellow programmers, and talk with each other. Use simple design
and programming practices, and simple methods of planning, tracking,
and reporting. Test your program and your practices, using feedback
to decide how to steer the project. Working together in this way gives
the team courage. Weve found that many of the higher-ceremony
trappings of software projects are based on fear of the unknown that
fear is reduced or eliminated by XPs high communication, reducing
the need for those practices. Weve found that many such practices are
based on fear of losing we prefer to focus on winning, by delivering
what the customer wants, when he wants it, in a context of solid software enginerring.
195
Conclusion
196
Conclusion
organization, get the data, then adjust your process, keeping in mind
simplicity, communication, feedback and courage.
To become truly good at programming is a lifes work, an ongoing
enterprise of learning and practicing. To become good at Extreme Programming is much the same. In spite of the name, Extreme
Programming is about people as much as it is about programming, and
our relationships with other people are what life itself should be about.
We have enjoyed the journey so far, and sincerely hope that you will as
well. If we can help like the truth, were out there. Look us up.
197
Conclusion
198
Conclusion
199
Conclusion
200
Conclusion
201
Conclusion
202
Conclusion
203
Conclusion
204
Section I
Bonus Tracks
Here are some things weve paid a lot to learn. Since you
bought the album, we wanted to give you a little something
extra. Thank you, and we hope we passed the audition.
205
206
Chapter 24
Well Try
Well try can be the saddest words a programmer has ever
spoken, and most of us have spoken them more than once.
Weve covered this material in other forms already, but it
bears repeating here.
These words are often the preface to months of grueling effort against
a deadline we know in our heart we cannot make. At the end, we come
up tired, burnt out, beaten, and short. Management hates us, we hate
ourselves, our families don't know us any more or have fallen by the
wayside. The software, if it works at all, is nothing to be proud of.
Oh, there have been exceptions. Successful products have been
launched this way, and there is a certain pride in having gone through
hell and survived. We have to believe it was worth it, if the alternative
is to believe we wasted a big chunk of our lives.
There has to be a better way. Here's one that couldn't really happen.
Suppose you knew everything they were asking for, and suppose you
knew how long it would take your team to do every one of the things
they were asking for.
Suppose you knew that, and you weren't afraid of the truth. Suppose
you wrote down everything they were asking for, maybe on little cards,
and you went in to them and laid your cards on the table.
207
Well Try
Suppose you said: Here's everything you have asked for, and on each
card I've put down how long it is going to take to get done. I've broken them down into three-week periods, and in each period I've put as
many cards as will get done in that period. As you can see, it will take
14 periods to do all this.
You lay a pencil vertically between two of the columns, and say: Here's
the date we want to deliver. We have too much to do. Our job now is
to put the cards we want the most on the left side of the pencil. When
we put a card over there, we have to remove a card with the same number on it.
They rant. They rave. They call you names. Secure in your perfect
knowledge, you say, This is how long each of these things will take. To
get the best product by our date, we need to put the cards we want
most on the left side of the pencil, removing cards with the same
number.
They threaten your job. You say, trying not to smile, This is how long
it will take our current team to do it. Maybe if you fire us, you can
find, recruit, hire, and train a team that will get it done sooner.
Bask for a moment in how calm, how strong, how totally cool and
heroic you would be, because you know how long it will take.
But that couldn't happen, could it? Yes, it could. We may not be able
to do as well as the lucky devil above, but it turns out we can do pretty
well. Here's how an XP team does it:
For a moment, get in touch with that feeling you have when you're
just coding along. The world goes away, you code and test and test and
code, and quickly you're done with whatever it is.
A day of that is what we call a Perfect Engineering Day. For a lot of
your tasks, you probably have a solid feeling: If you guys would just
leave me alone, I could do that in two days!
208
Well Try
Well Try
Well Try
211
In this book, theres more about estimation in Iteration Planning (page 79), Experience
improves estimates (page 155), and How to estimate anything (page 217).
Well Try
212
Well Try
You're asking how this could possibly work. The amazing thing is that
it actually works pretty well, even for your first estimate of the project.
But what makes it really work is that you do it again and again.
When you present your first Release Plan, explain to management how
you got the schedule. Then tell them that you do not believe this
schedule, and that neither should they. You go on:
Many things can, and will change in the course of this development.
Customers will change requirements, some things will turn out to be
easier than we thought, and some will be harder. That has happened in
every project we have ever done, and it will happen this time.
The difference with this project is that we will do this schedule every
nine weeks as we go along, and we will report the results to you. We
will refine all our estimates of the remaining stories, based on what we
have learned in the preceding iterations. Each time we get together, we
will all see how many stories are done, and how many there are to go.
Each time we get together, expect to see that we are closer to completion. Expect also that the date may move in, and it may move out. But
you will be able to see exactly what our estimate is, and that will enable
you to make good decisions about the project.
We're confident that we can give you quality information about how
we're doing, and we're confident that with that information you will
have the best chance of helping us be successful.
And you will do just that: you will observe your own performance, and
you will estimate the stories over again based on what you know, and
every two months your ability to estimate the schedule will get better
and better.
Even better, customers and management will learn that you are telling
the truth as you know it; they will learn that your estimate of the
schedule is the best they can get; they will learn that they can help with
the delivery by providing you what you need, and by adjusting scope
judiciously to help you make the date.
213
Well Try
This is a reference to bailing out of an airplane. Used back when Jeffries was a boy.
214
215
Well Try
Well Try
216
Chapter 25
218
Chapter 26
Infrastructure
What about that database you need to build first? What
about that framework? What about that syntax-directed
command compiler? Get over it!
All too often, projects go dark for a few months at the beginning while
they build some absolutely necessary bit of infrastructure. Usually the
team really believes that its necessary, and that it will make things go
faster in the long run.
YAGNI: Youre Not Gonna Need It. This slogan, one of XPs most
famous and controversial, reminds us always to work on the story we
have, not something we think were going to need. Even if we know
were going to need it.
XPs planning process works by allowing the customers to steer all of
development, based on business value. If we wait for a few months not
delivering business value, were violating that process and losing the
customers interest and confidence. We may never get it back. Some
projects never emerge from this cave of darkness. Dont go in there.
Some teams address infrastructure by allowing some percentage of
programmers time to go to infrastructure tasks. We need a database,
so well put two programmers worth of work on it in every iteration.
Thats two for us, and the remaining six for the customer. This is a bit
better, but frankly, its a slippery slope.
219
Infrastructure
One project we know of took 100 percent of one of its final iterations
on infrastructure issues. This really confused the customers, who had
had stories in mind for that iteration. Doctor, it hurts when I confuse
my customers.1
Where possible, associate infrastructure work with specific stories that
the customer wants. One of our favorite examples is this one: the programmers realized that they needed to write some scripts to check
whether input data files were available and FTP them to the server.
They couldnt think of any way to associate this with business value.
Finally, someone got the answer. The story was When we (the customers) show up in the morning at 8 AM, the data is there live on our
systems. Naturally, the customers wanted this they gave it a very
high priority. And this story served quite well as the basis for the tasks
of writing the tasks.
Use this trick ruthlessly. Every time you are thinking of some big infrastructure investment that you may have to make behind the scenes,
tie it back to customer business value. If you cant, maybe the customer doesnt need it. If the customer doesnt need it, dont do it.
OK, youve got it tied to a story: The system records name, address,
age, height, weight, and a lot of other personal information for each of
10 million patients. It can display any patient by record number and
can display statistical analyses for any and all stored data. It knows
everything that has ever happened to any patient at any time. And
thats just the beginning.
OOPS, clearly we need a database. Or do we?
First of all, that story is too big to estimate. Lets break it down. Here
are a couple of the new stories:
The system records name, address, age, height, and weight for
patients.
1.
If you dont know this joke, email us. No, on second thought, Dont do that.
220
Infrastructure
Infrastructure
type, and one place that writes it. Those places will converge down to
just one place that reads an arbitrary record and just one that writes.
Those are the places the only places where the database access
code will have to go.
Now as you begin with XP, we realize youll have trouble fully signing
up for this philosophy. At first youll feel the need to do some amount
of infrastructure work, and youll have to find some technique to avoid
going completely dark on your client. Maybe the level of effort thing.
But where possible, associate infrastructure explicitly with customer
value. And where possible, do infrastructure tasks very incrementally, a
little bit with each story. When your courage is high, try extra simple
solutions, then watch how they work out. If your anxiety level gets
high, go ahead and put in as much generality as you think you need
but just enough for right now.
Observe what happens. Were sure youll find that you dont need to
invest as much in the future as you used to, and that things will actually
go more smoothly in the process. As you go along, put more and more
simplicity in at the beginning, relying on your ability to refactor to add
the generality or the general tools that youll need.
222
Chapter 27
Another was the famous Balancing Hopes and Fears (page 225), where Chet snatched the
stone from the very hand of Beck himself.
223
224
Chapter 28
Those of you who have heard Ron, Ann, or I speak about XP are probably wondering where are all the war stories. Well, heres one.
C3 was about ready to launch, the acceptance tests where in the low
nineties and moving steadily upwards, performance was within acceptable levels. But we had one hole. Early in the project, we had decided
to retain the reporting portions of the legacy system. This would allow
us control the new systems interface, and maybe, launch the first
phase of the system much quicker. Unfortunately, that interface contained several hundred poorly understood data items. And it is difficult
to write acceptance tests when the customer doesnt know what the
data means let alone what the correct value is.
So here we were, all of our measures were pointing to a launch in the
near future, but we all knew our biggest risk was not showing up on
our charts. We knew it, but we didnt want to know it. And so we lied
to ourselves, or at least we didnt tell ourselves the complete truth.
About this time Kent made one of his periodic visits and after assessing
the situation, called us all together. We then had the most uncomfort225
226
Chapter 29
We had written a little workspace code to make sure we had the algorithm right, but now we needed to write a unit test. The method we
had written was self-contained; all the information we had needed was
stored as instance variables on the class. So to test it we would have to
create a series of SharedManagedPopulations, each with a collection of
227
Disclosures, each with the appropriate numberOfThreads and threadNumber. That seemed like too much work to us, so we decided to
refactor the code to make it easier to test.
SharedManagedPopulation>>intervalForThread: threadInteger
numberOfThreads: threadTotalInteger
collectionSize: sizeInteger
|slice start end|
slice := sizeInteger // threadTotalInteger.
Start := (slice * threadInteger) + 1.
End := (start + slice) max: sizeInteger.
^Interval
from: start
to: end
SharedManagedPopulation>>intervalToProcess
^self
intervalForThread: threadNumber
numberOfThreads: numberOfThreads
collectionSize: disclosures size
difficulty writing the test, refactor the code to split out the behavior.
And secondly, if you find yourself needing to split out the behavior to
improve testability, write the test first. In either case, you will discover
that testing will improve the quality of your code.
229
230
Chapter 30
The first attempt at making and testing this change was a nightmare.
The connection parameters resided in one of the java classes. A duplicate file directory structure was copied on the test Unix server to
accommodate the changes being made to the SSJS and the java classes.
Changes to the files were being made using vi on the test machine.
Since the test server did not have the correct environment to test the
change (no comment on this one), the files were then moved to a
pre-production machine. A make-file was run that compiled and linked
all the associated files together. The web server then had to be stopped
and restarted for the changes to take effect. The web browser then was
engaged through a special port (set up for testing) that started the
application.
This totally unacceptable. Each code change required five to ten minutes to verify its effects. Three developers spent three days mucking
around in all this code. The only error message displayed in the
browser was Exception 52 (translated: The LDAP server is unavailable). The end result was three days of frustration and nothing
accomplished (except knowing what a 52 LDAP exception is). As a
bonus, all that hacking and slashing of files and directories corrupted
the already unstable environment and the server was unavailable for
over a week.
What we were missing were some good testing tools. The developers
in the group were used to writing applications in scripting languages
like SSJS and PERL. And boy did they love coding in vi! Coming
from a Smalltalk environment, I was used to working in a great IDE
and being able to step through RUNNING code to help debug problems. So I knew there had to be another way.
I purchased a copy of Visual Age for Java Professional Edition (VAJ)
and installed it on my PC. I then went to the Xprogramming site and
downloaded the JUnit testing framework. I imported the framework
into VAJ and spent a few hours familiarizing myself with it. I had spent
three years using the Smalltalk version so the mechanics of how it
worked was pretty easy to follow.
232
Having used ENVY/Developer for many years, I was also familiar with
the paradigm on which VAJ operated. I immediately felt the power of
knowing that all the java code I wrote would be in a code repository
and I wouldnt be dealing with files all over the place. And version
control would be greatly simplified.
Our applications interface to LDAP was localized through java classes.
The first thing I did was try and import the three classes that had been
developed specifically for the application. The exceptions I got trying
to import stated that netscape.ldap.* was not visible. I then went to
the Netscape web site and downloaded their Directory SDK. It came
with 2.jar files that contained all the.class files from the SDK. So, as a
first step I imported the 2.jar files into VAJ. No problems there. I then
tried again to import our three application classes. Success! At least
they were imported without any errors.
The next step was to browse the code and try to make a little sense of
how it all operated so I could start writing some unit tests. The two
immediate advantages I had at this point were being in a good editor
and having VAJ browser tools at my disposal. Unlike the generic vi,
the ability to double click inside a pair of {} brackets and have the
entire block of code between them highlighted made reading code
much easier. The availability of the search tools in VAJ was what really
made things fly. Being able to open a class browser on referenced
classes and find senders and implementers of methods in a unified environment makes you realize that there is no other way to do it.
I have to admit that within an hour I had a much better knowledge of
how the code all fit together than I had after three days of looking at
java code in vi in different files and trying to piece it all together. (As
you can tell I am a tool guy).
It was now time to write a unit test. I figured I should be able to get a
simple test written that used the untouched imported code to connect
to our own LDAP and return a UserData object. Since I was running
VAJ on my local Windows95 PC and the LDAP directories were on
our pre-production unix servers I at first thought that I would have to
set up some kind of local LDAP test server. But I decided against that
233
strategy. One of our XP mottoes was let Smalltalk tell you. Even
though this was java, I knew that if there was a problem, the code
would tell me. I knew how VAJ worked and that it would actually help
me find any problems.
First I built a test case called LdapTest (subclassed from TestCase). I
then took the SSJS code that instantiated an LdapServer object and
put it in the setUp() method of the test:
public void setUp() {
ldapServer = new LdapServer();
}
Since I had configured VAJ with JUnit as a tool, I simply right clicked
on the LdapTest class and selected Tools>Junit. The JUnit gui opens
and automatically runs the test. The best part of all this was that the
progress bar came up green.the test had run!! And it ran in 0.054
seconds. A few hours of work and I now had a repeatable test that
would test any changes I made to the Ldap classes. I think that is a
good thing. I then expanded the number of assertions to test every
piece of data the UserData object is supposed to retrieve.
Now that the test was up and running, I placed a breakpoint at the
start of the test and was able to step through the running code. There
is no better way to decipher how an application works than to watch it
do its thing. The reaction from other members of the team was immediate. They realized that debugging time in this environment would be
only one-tenth of what it was currently. After watching me for that one
day writing tests and stepping through code, another member of the
234
team took a small java application he had written, imported the code
into VAJ, and spent time walking step-by-step through the code he
had written.
Now I set my sights on the task at hand. I needed to change the code
to point to the new corporate LDAP directory server. The LdapServer
creates an instance of LdifServer which actually does the LDAP interfacing. After reviewing how LdifServer worked (by stepping through
the unit tests), I realized that a refactoring of the class was needed to
proceed. And with my unit tests in place I knew it would be a snap.
Here is what LdifServer looked like before I started:
private void openConnection() {
_conn = new LDAPConnection();
try {
_conn.connect("oddshpr1-nf0.oddc.company.com",
389);
_base = "o=American Corporation, c=US";
_scope = LDAPv3.SCOPE_SUB;
}
catch(Exception ex) {
System.out.println(ex);
return;
}
}
public UserData getUserData(String tid) {
openConnection();
String filter = "(&(objectclass=companyPerson)" +"(uid=" +tid +"))";
String attrs[] = { "givenName", "sn", "employeeNumber",
"nationality",
"destinationIndicator", "cn", "employeeType",
"dsHasAgreed" };
boolean attrsOnly = false;
LDAPSearchConstraints cons = _conn.getSearchConstraints();
LDAPSearchResults results;
UserData data = null;
try {
results = _conn.search(_base, _scope, filter, attrs,
attrsOnly, cons);
235
if(!results.hasMoreElements()) return(null);
LDAPEntry entry = results.next();
LDAPAttributeSet attribs = entry.getAttributeSet();
String givenName = getValue(attribs, 0);
String sn = getValue(attribs, 1);
String employeeNumber = getValue(attribs, 2);
String nationality = getValue(attribs, 3);
String plant = getValue(attribs, 4);
String cn = getValue(attribs, 5);
String employeeType = getValue(attribs, 6);
boolean isEmployee =
!(employeeType.equalsIgnoreCase("N/A"));
boolean policyFlag = getValue(attribs,
7).equalsIgnoreCase("true");
data = new UserData(tid, givenName, sn, null, isEmployee,
employeeNumber, nationality, plant, cn, employeeType, policyFlag);
}
catch(Exception ex) {
try {
System.out.println("Exception: " +ex );
}
catch(Exception ex2) {
}
}
return(data);
}
As you can see, the code was a mess. Not only was it hard to follow,
but the individual pieces were impossible to test. Without getting into
too much detail of how the LDAP interface works, the LdapConnection executes a search() function that takes a whole bunch of
parameters. These parameters specify which Ldap directory server to
connect to and what attributes to retrieve. It was obvious that refactoring the search attributes would make it possible to subclass LdifServer
and override the connection parameters.
Heres what I ended up with:
private void connect() {
try {_conn.connect(ldapServer(), ldapPort());
236
}
catch(Exception ex) {systemOut(ex);
}
}
public String ldapServer() {
return "oddshpr1-nf0.oddc.company.com";
}
public int ldapPort() {
return 389;
}
Since I had written my new unit test, I just hit the Run button and,
what do you know, the test ran! That wasnt so hard. I decided to
refactor the other method so I could test it thoroughly.
public UserData getUserData(String tid) {
LDAPSearchResults results = null;
LDAPEntry entry = null;
try {results = search(tid);}
catch(Exception ex) {systemOut(ex);}
if(!results.hasMoreElements()) return(null);
try {entry = results.next();}
catch(Exception ex) {systemOut(ex);}
UserData data = newUserData(entry);
return(data);
}
public LDAPSearchResults search(String tid) {
LDAPSearchResults results = null;
try {results = _conn.search(ldapBase(),
237
ldapScope(),
ldapFilter(tid),
ldapAttributes(),
ldapAttributesOnly(),
ldapSearchConstraints());}
catch(Exception ex) {systemOut(ex );}
return(results);
}
I was now able to write more unit tests for each piece of the puzzle.
Here are a few examples:
public void testLdapConnections() {
LdifServer ldifServer = new LdifServer();
assert(ldifServer.connection().isConnected());
try {ldifServer.connection().disconnect();}
catch(Exception ex){};
assert(!ldifServer.connection().isConnected());
try {ldifServer.connection().connect(ldifServer.l dapServer(),
ldifServer.ldapPort());}
catch(Exception ex){};
assert(ldifServer.connection().isConnected());
assertEquals(ldifServer.ldapPort(), 389);
assertEquals(ldifServer.ldapScope(), 2);
assertNull(ldifServer.ldapAttributes());
assert(!ldifServer.ldapAttributesOnly());
assertNull(ldifServer.newUserData(null));
}
public void testLdapSearch() {
LdifServer ldifServer = new LdifServer();
LDAPSearchResults results = ldifServer.search("t4321rg");
assert(results.hasMoreElements());
}
public void testNullLdapSearch() {
LdifServer ldifServer = new LdifServer();
UserData data = ldifServer.getUserData("TestNullReturn");
assertNull(data);
}
238
After more refactoring and more tests, we were ready to move from
the test environment to real time. I exported the *.class files from
Visual Age and replaced the ones on the server. Then I logged into the
application. To my complete and utter non-surprise, it worked! This
compared to three days of hassle on the previous attempt with NO
success and no clues. A days worth of coding, testing, and refactoring
had gotten the job done.
239
240
Chapter 31
A Java Perspective
We would like to thank Bill Wake for allowing us to use his
article. It is the second in a series entitled "The Test/Code
Cycle in XP". His website http://users.vnet.net/wwake
contains the entire series plus a whole lot more.
People who unit-test, even many who unit-test in Extreme Programming, dont necessarily test the user interface. You can use JUnit to
assist in this testing, however. This paper will work through a small but
plausible example, giving the flavor of testing and programming using
JUnit. This paper is part 2, but can be read on its own; part 1 developed the model.
Example
Suppose were developing a simple search engine. Wed like the user
interface to look something like this:
241
A Java Perspective
Well develop it in the XP style, working back and forth between testing and coding. The code fragments will reflect this: tests will be on
the left side of the page, and application code on the right.
Model First
When youre creating a GUI (graphical user interface), you should
develop and test the model first. Well assume this has been done, and
that it has the following interface:
public class SearcherFactory {
public static Searcher get(String s) throws IOException {...}
}
public interface Searcher {
public Result find(Query q);
}
public class Query {
public Query(String s) {...}
public String getValue() {...}
}
public interface Result {
public int getCount();
public Document getItem(int i);
}
public interface Document {
public String getAuthor();
242
A Java Perspective
A Java Perspective
assertNotNull(panel.resultTable);
}
A Java Perspective
Testing Interconnection
Somehow, we must associate a Searcher with our GUI, and verify that
we display its results.
Well give our panel two methods, getSearcher() and setSearcher(),
that will associate a Searcher with the panel. This decision lets us write
another test:
public void testSearcherSetup() {
Searcher s = new Searcher() {
public Result search(Query q) {return null;}
};
SearchPanel panel = new SearchPanel();
assert ("Searcher not set", panel.getSearcher() != s);
panel.setSearcher(s);
assert("Searcher now set", panel.getSearcher() == s);
}
245
A Java Perspective
Go through the usual compile/fail cycle, and create the test classes,
starting with TestDocument:
public class TestDocument implements Document {
int count;
public TestDocument(int n) {count = n;}
public String getAuthor() {return "a" + count;}
public String getTitle() {return "t" + count;}
public String getYear() {return "y" + count;}
246
A Java Perspective
The TestResult class has a constructor that takes an integer telling how
many rows should be present:
public class TestResult implements Result {
int count;
public TestResult(int n) {count = n;}
public int getCount() {return count;}
public Document getItem(int i) {return new TestDocument(i);}
}
TestSearcher uses the number value of the query string to create the
result:
public class TestSearcher implements Searcher {
public Result find(Query q) {
int count = 0;
try {count = Integer.parseInt(q.getValue());}
catch (Exception ignored) {}
return new TestResult(count);
}
}
0, 1, Many
Well build tests for the 0, 1, and many cases:
public void test0() {
SearchPanel sp = new SearchPanel();
sp.setSearcher (new TestSearcher());
sp.queryField.setText("0");
sp.findButton.doClick();
assert("Empty result", sp.resultTable.getRowCount() == 0);
}
At last, were using the GUI: setting text fields, clicking buttons, etc.
247
A Java Perspective
We run the test - and it passes! This means we already have a working
solution - if our searcher always returns 0 items.
We move on:
public void test1() {
SearchPanel sp = new SearchPanel();
sp.setSearcher (new TestSearcher());
sp.queryField.setText("1");
sp.findButton.doClick();
assert("1-row result", sp.resultTable.getRowCount() == 1);
assertEquals(
"a0",
sp.resultTable.getValueAt(0,0).toString());
}
A Java Perspective
Adapter Implementation
Lets write the button code as if a ResultTableAdapter class existed:
findButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Query q = new Query(queryField.getText());
resultTable.setModel(
new ResultTableAdapter(getSearcher().find(q)));
}
});
249
A Java Perspective
implement the column names, column and row counts, and finally
getValueAt().
public class ResultTableAdapter
extends AbstractTableModel implements TableModel {
final static String columnNames[] = {"Author", "Title", "Year"};
Result myResult;
public ResultTableAdapter(Result r) {myResult = r;}
public String getColumnName(int i) {return columnNames[i];}
public int getColumnCount() {return columnNames.length;}
public int getRowCount() {return myResult.getItemCount();}
public Object getValueAt(int r, int c) {
Document doc = myResult.getItem(r);
switch(c) {
case 0: return doc.getAuthor();
case 1: return doc.getTitle();
case 2: return doc.getYear();
default: return "?";
}
}
}
A Java Perspective
A Java Perspective
display.setSize(500,500);
display.setVisible(true);
//try {Thread.sleep(3000);} catch (Exception ex) {}
assert ("label left-of query",
sp.searchLabel.getLocationOnScreen().x
< sp.queryField.getLocationOnScreen().x);
assert ("query left-of button",
sp.queryField.getLocationOnScreen().x
< sp.findButton.getLocationOnScreen().x);
assert ("query above table",
sp.queryField.getLocationOnScreen().y
< sp.resultTable.getLocationOnScreen().y);
}
The test fails, as we havent done anything to put widgets on the panel.
(You can un-comment the sleep() if you want to see it on-screen.)
To implement panels, I usually do a screen design that shows the intermediate panels and layouts:
252
A Java Perspective
253
A Java Perspective
this.add(new JScrollPane(resultTable),
BorderLayout.CENTER);
}
Main
To complete the system, well create a main() routine:
public class Main {
public static void main(String[] args) {
if (args.length == 0) {
System.err.println(
"Arg - file w/tab-delimited author/title/year");
System.exit(1);
}
Searcher searcher = null;
try {
searcher = SearcherFactory.get(args[0]);
} catch (Exception ex) {
System.err.println(
"Unable to open file " + args[0] + "; " + ex);
System.exit(1);
}
SearchPanel sp = new SearchPanel();
sp.setSearcher(searcher);
JFrame display = new JFrame("Bibliographic System - " +
args[0]);
display.getContentPane().add(sp);
display.setSize(500,500);
display.setVisible(true);
}
}
Conclusions
254
A Java Perspective
Resources
code for this example can be found on
http://users.vnet.net/wwake.
The Test/Code Cycle in XP: Part 1, Model, William Wake, found on
http://users.vnet.net/wwake.
Extreme Programming Explained, Kent Beck.
Refactoring, Martin Fowler.
JUnit can be found on http://www.XProgramming.com.
Copyright 2000, William C. Wake, used with permission.
[email protected]
255
A Java Perspective
256
Chapter 32
A True Story
Ron Jeffries [re]learns something about simplicity.
We are writing this book using Adobe FrameMaker. Frame, as we
affectionately call it, lets us store the chapters in individual files and
organize them into a book in a separate book file. It turns out that we
could use a little extra automation of our work, so I thought Id just
code up a little application. I wrote a few stories here are a couple:
Report which files in the book directory arent actually used in
the book file. Ignore the backup files.
After adding and updating chapters, send just the files that have
changed to Chet and Ann.
Were in the midst of a fairly large reordering of chapters, and I really
wanted the list of files that exist but arent in the book. Last night I set
out to implement that story in Dolphin Smalltalk. (Dont worry, Im
not going to make you read the code.)
It turns out that Dolphin doesnt have an object that represents a file
directory or folder. It can give you a list of file specs that match a
pattern. Well, obviously Im going to need a Directory object, so I
started on it last night. I wrote some tests, some code, and got a
decent start at it. I put a few hours into it, and it was a bit harder than
I thought, and I hadnt even gotten to the idea of a Directory holding
another Directory. So I posted a question on the Dolphin news group,
and went to bed.
257
A True Story
This morning I still wanted the list of files that werent in the book,
but I had come to my senses. The value was in that list of files, not
some general support for directories. I went back to the story: report
which files in the book directory arent in the book file.
I created a test for a BookAnalyzer object. The test checked to see if
the analyzer could learn which files were used. This was easy, as theres
a script from Frame that writes that information out to a text file. That
test was running in no time.
Then I wrote a test that asks the BookAnalyzer for the unused files.
I implemented that by intention, by asking for the chapter files and
removing all the used files. I implemented the chapter files by asking
for the .fm files and removing all the backup.fm files. I implemented the .fm files by getting the list of file specs from the book
directory that matched *.fm.
Well, guess what. Done in an hour, works perfectly, and doesnt need a
Directory object at all.
I put a couple of chapters in that had been missed, deleted a couple of
files that were no longer relevant, and got on with business.
Now in microcosm there are some important lessons here, lessons I
need to relearn time and again:
I was working alone. A partner might have kept me from starting.
Surely a partner would have gotten bored with messing with Directory for so long.
Small releases provide immediate business value. I got and used the
info I really needed with my small project this morning.
Simple solutions are faster. The BookAnalyzer got done in half the
time I put into Directory, which still isnt done.
You might have one major concern didnt I wind up with some very
specialized and hacked-together code, instead of the Directory object I
will really need some day?
258
A True Story
259
A True Story
260
Chapter 33
Heres what programmers can promise, and what the practices in this
book will help deliver:
1. You can promise to estimate the difficulty of the entire project, each
story in the project, and each task in each story, as accurately as you
can.
2. You can promise to track those estimates to improve your ability to
know how hard things are going to be.
3. You can promise to track delivery performance, to make it clear
how fast the project is really going.
4. You can promise to use the facts to refine the picture of when the
project will be done, by estimating again as you learn, and by using
the velocity so far to predict where youll be by any given date, or
to predict the date when youll have chosen features done.
263
264
Chapter 34
265
266
The rule is to test everything that could possibly break. To save time,
don't test things that couldn't possibly break. There are more things
that couldn't possibly break than you might imagine.
Start conservatively on identifying things not to test. Until you're sure,
test. But unit testing is white box testing. You look at the code when
you write the test, and if the code can't break - don't test it.
Accessors can't break. There's no need to test them. Unless, of course,
you have a tendency to forget to write them, and no other test is going
to find that they're missing. But wait - if no other test is going to
access them, they shouldn't be there anyway. So probably you don't
need to test accessors.
Even if it's more complex, sometimes code just can't break. Here's an
example in Smalltalk:
printAccounts
accounts do: [ :each | each print]
That method loops over the collection named accounts, and tells each
account to print. The method can't possibly break. There are other
things that could break: accounts might not be a collection, and
depending on the code you might need to test that. Accounts might
not know how to print themselves, or their printing might break. You
might need to test that. But, in my opinion, you don't need to test the
printAccounts method. (Just my luck there'll be a bug in it. Well, live
and learn.)
I (Jeffries here) used to teach that if an object was used extensively in
other objects, maybe you didn't need to test it directly. I'm not so sure
any more. Just the other day, looking at a client's code, I found an
object that needed some work to be really good code. I grabbed a
partner and we sat down to work. First thing we noticed was that the
object wasn't directly tested. It was exercised rather fully by the test for
another object, but when we got to refactoring the first object, it
didn't seem that those tests were correctly aimed. So we wrote some
267
268
We have written two tests, one that checks an Account with no entries
(written mostly because it was the simplest test that we could think of),
and one that checks an Account with three entries:
TestCase subclass: #AccountTest
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''!
!AccountTest methodsFor!
testEmpty
self should: [Account new balance = 0]!
269
testThree
| account |
account := Account new.
account add: (Transaction deposit: 100).
account add: (Transaction withdraw: 15).
account add: (Transaction withdraw: 25).
self should: [account balance = 60].! !
The class contains transactions. We'll see below that these are an
OrderedCollection (similar to Java Vector).
add: aTransaction
self transactions add: aTransaction!
This method gets the transactions collection (see below), and adds the
method parameter, aTransaction, to the collection. The method add: is
standard behavior on OrderedCollections, and can add anything at all
to the collection.
balance
^self transactions
inject: 0
into: [ :sum :each | sum + each value]!
that this will be a positive number for a deposit and a negative number
for a withdrawal.)
transactions
transactions isNil ifTrue:
[transactions := OrderedCollection new].
^transactions! !
That leaves us with the system problems like What if someone creates
a non-transaction and sends it to an account? Well now. Any class that
(thinks it) is creating Transactions and putting them in Accounts must
have a test. Would it be hard to test? We don't know, but our rule is
that we must test everything about it that could possibly break. If the
code visibly started with numbers and created Transactions with
deposit: and withdraw:, it would probably be pretty clear how much to
test.
So we assert with confidence and no proof that the AccountBuilder (or
whatever it might be) would also be easy to test everything that could
possibly break.
And finally, remember that there are acceptance tests as well. These are
designed to test whether the system, in actual use, every gets wrong
answers or blows up. If/when these tests found something, they would
point, almost inevitably, to a particular class (like AccountBuilder) that
was doing something wrong, i.e. that wasn't tested enough. We would
(a) learn something about what to test in such classes, (b) add the necessary test[s], and (c) add similar tests everywhere we thought we
needed them.
In no case, it seems to me, are we likely to run into combinatorial
problems, problems of writing an infinite number of tests, or such.
There's just no place for them to happen - wherever we invoke them,
we are writing a class, and that class can support a sensible and quite
finite collection of tests.
Now, of course, this is just a simple example. But in my strong opinion, it is not at all atypical. Most everything one ever needs to do can
be built this simply, and incrementally, and testably. None of us always
does it, but each of us nearly always could, and would benefit if we did.
273
274
Annotated
Bibliography
The purpose of this section is to give you a chance to dig deeper
into the aspects of XP that interest you, and to see some of the
aspects of life that have brought the authors to this point.
Scott Adams, The Dilbert Principle, HarperCollins, 1996; ISBN
0-88730-787-6.
Bill Rogers, Rons old mentor, always used to say You have to either
laugh or cry. Join Scott Adams and Dilbert, and laugh.
Robert C. Atkins, M.D., Dr. Atkins New Diet Revolution, Avon Books,
1999; ISBN 0-71001-00750-3.
Dont ask.
Kent Beck, Extreme Programming Explained, Addison-Wesley, 2000,
ISBN 0-201-61641-6.
The book that started XP happening. We are pleased to have been
there while it happened. Thank you, Kent.
________, Smalltalk Best Practice Patterns, Prentice-Hall,1996; ISBN
013476904X.
275
276
278
Daniel P. Freedman, Gerald M. Weinberg, Handbook of Walkthroughs, Inspections, and Technical Reviews, Dorset House, 1990, ISBN 0-932633-19-6.
XPs Pair Programming obviates the need for most inspections and reviews.
If you must do them, do them right. Freedman tells you how.
Erich Gamma, Richard Helms, Ralph Johnson, and John Vlissides, Design
Patterns, Elements of Reusable Object-Oriented Software, Addison-Wesley, 1995;
ISBN 0-201-63361-2.
A collection of key design patterns, providing description of problem and
solution. These patterns now serve as the official terminology for these
ideas. Know them and use them in your designs. If you cant quote from this
one, your computer geek friends will make fun of you.
Roger Garrett, Starship Simulation, dilithium Press, 1978, ISBN
0-918398-10-X.
Designing and implementing a simulation of a starship on a personal computer. We want to play this game!
Donald C. Gause and Gerald M. Weinberg, Are Your Lights On?: How to Figure Out What the problem Really Is, Dorset House, 1990; ISBN 0932633161.
This is a fun book about problem solving and creativity.
Thomas Gilb, Principles of Software Engineering Management, Addison Wesley Longman, 1988; ISBN 0201192462.
Tom Gilb is very much into incremental development, and measurement.
Check him out!
Malcom Gladwell, The Tipping Point, Little, Brown, 2000; ISBN
0-316-31696-2.
How do fashion trends come to be? How are unknown books transformed
into best sellers? How do software development processes become used
world-wide, making the universe safe for programmers? Gladwell tells us of
Connectors, Mavens, Salesmen, and the Stickiness Factor. Does XP have all
those? We hope so.
James Gleick, Genius: The Life and Science of Richard Feynman, Pantheon,
1992; ISBN 0679408363.
The story of one of the great minds of the 20th century. The man who used a
spike solution to discover why the shuttle Challenger exploded.
281
Adele Goldberg and David Robson, Smalltalk-80: The Language, Addison-Wesley, 1989; ISBN 0201136880.
If you use Smalltalk, you know the purple book. If you are just wondering
why we wont let it go, here is the bible.
Stephen Jay Gould, The Mismeasure of Man, Norton, 1996; ISBN
0393314251.
Science has spent the last 150 years trying to measure human intelligence by
using everything from the volume of our skulls to our ability to fill-in little
circles with a #2 pencil. An important lesson for all of us who want to measure performance.
David Halberstam, The Reckoning, Morrow, 1986, ISBN 0688048382.
U.S vs Japan, Ford vs Nissan, I never would have guessed Ford would win.
Wonderful insights into late 20th century American industrial management
techniques. When the car guys wanted money to build bigger paint ovens,
Ford President Robert McNamara suggested cutting the cars in half before
painting them. I guess it also explains a lot about Viet Nam.
Gay Hendricks, Ph.D. and Kate Ludeman, Ph.D., The Corporate Mystic, Bantam Books, 1996; ISBN 055337494X.
One of the groups I work with recommends this book to all of their employees.It addresses integrity, leadership, working with others. Excellent.
James A. Highsmith III, Adaptive Software Development, Dorset House, 1999;
ISBN 0-932633-40-4.
Jims Adaptive Software Development describes how to bring teamwork,
speed, and adaptability to larger-scale projects. Wed say that he copied our
ideas, except that he got there first. Powerful and deep material in a compact
and readable form.
Watts S. Humphrey, Managing Technical People, Addison-Wesley, 1997;
ISBN 0-201-54597-7.
Good thoughts on group dynamics, innovation, and process. As one might
expect from the SEI part of the world, somewhat oppressive, and aimed at
larger groups than we address.
________, The Personal Software Process, Addison-Wesley, 1997; ISBN
0-201-54809-7.
If you knew all these things about your programming, youd know something good. You could also win the retention medal for America in the
282
upcoming Olympics. Good ideas, good focus on personal skill. Rather regimented.
Andrew Hunt and David Thomas, The Pragmatic Programmer, Addison-Wesley, ISBN 0-201-61622-X.
A delightful book, demystifying much of programming, bringing it down to
earth. Pragmatic Dave, as we call him to distinguish him from other
important Dave Thomases, has been an active questioner, indeed inquisitor,
and has helped us sharpen our understanding of our ideas. Very XP compatible.
Carole Jackson, Color Me Beautiful, Ballantine Books, 1980; ISBN
0-345-29015-1.
Why does Jeffries wear so much black? Hes a Winter!
Ricky Jay, Cards as Weapons, Warner Books,1988; ISBN 0446387568.
An early precursor to the use of cards for planning and design. Ricky Jay is
one of the premier card users of all time.
Bill Jensen, Simplicity, Perseus Books, 2000; 0-7382-0210-X.
Making the complex clear always helps people work smarter. Because it is
a lot easier to figure out whats important and ignore what isnt.
Joseph L. Jones and Anita M. Flynn, Mobile Robots, Inspiration to Implementation, A K Peters, Ltd., 1993, ISBN 1-56881-011-3.
How to build two inexpensive robots, essentially from scratch. Heres a book
about a toy you really need!
Wolfgang Langewiesche, Stick and Rudder, An Explanation of the Art of Flying, McGraw-Hill, 1944, 1972; ISBN 0070362408.
Kent tells a story about learning to drive and how that lesson influenced his
ideas on project management. Knowing XP before learning to fly, has made
me more aware of their similarities.
Richard A. Lanham, Revising Business Prose, Macmillan Publishing Company, 1992; ISBN 0-02-367480-6.
As we revised this book, we tried to follow Lanhams advice. The book is
short, and simple, and follows its own advice.
Brian W. Kernighan and Rob Pike, The Practice of Programming, Addison-Wesley, 1999; ISBN 0-201-61586-X
283
284
Glenford J. Myers, Reliable Software through Composite Design, Mason/Charter Publishers, 1975; ISBN 0-88405-284-2.
Together with Constantines work on Structured Design, one of the seminal
works on modularity. High cohesion, low coupling, just how to build good
objects even today.
Miyamoto Musashi, A Book of Five Rings, The Overlook Press, 1974; ISBN
0-087951-018-8.
Originally written in 1645, this book hold the philosophy of Japans most
renowned warrior. He intended this book for any situation where plans and
tactics are used. Its no longer acceptable to kill your programmers with
swords, but this is a fascinating book.
Sarah OKeefe, FrameMaker 5.5.6 for Dummies, IDG Books, 1999;
0-7645-0637-4.
The one book without which this one could not exist. This, and Extreme
Programming Explained. The two books ... oh never mind. Sarah saved our
bacon. Thanks, Sarah.
Mark C. Paulk, et al., The Capability Maturity Model, Addison-Wesley, 1995;
ISBN 0-201-54664-7.
This isnt just know thy enemy. Yes, CMM can be, has been, and will be
misused. However, the goals and the generic activities of CMM are consistent with quality, and worth thinking about. We think you can do without
most of the practices, in most situations, but keep them in mind for those
sticky situations.
M. Scott Peck, M.D., The Road Less Travelled, Simon and Schuster, 1978;
ISBN 0-671-25067-1.
There comes a time when we need to take a look at our lives.
Ayn Rand, The Fountainhead, Penguin Books; ISBN 0-451-19115-3.
________, Atlas Shrugged, Penguin Books; ISBN 0-451-19114-5.
Individual responsibility and individual mastery are at the core of team performance. It doesnt hurt to start with Rands vision of the competent man.
Just dont stop there.
James Rumbaugh, Michael Blaha, WilliamPremerlani, Frederick Eddy, and
William Lorenson, Object-Oriented Modeling and Design, Prentice Hall, 1991;
ISBN 0136298419.
285
Elaine St. James, Simplify Your Life: 100 Ways to Slow Down and Enjoy the
Things That Really Matter, Hyperion, 1994; ISBN 0786880007.
A small book with lots of advice for thinking about your life and what's
really important.
Michael Schrage, Serious Play, Harvard Business School Press, 2000; ISBN
0-87584-814-1.
Collaboration, play, Demo or Die. Learning what you want comes from
playing with what might be. Schrage offers prototyping as a way of life. XP
suggests making your prototypes real.
Philip Toshio Sudo, Zen Computer, Simon and Schuster, 1999; ISBN
0-684-85409-0.
This short book asks us to acknowledge the spiritual, meditative side of ourselves as we work with the computers we face every day. Its not deep, not
heavy. Rather, its mild and calming. Good preparation for facing the Blue
Screen of Death.
Guy L. Steele, Jr., the Hackers Dictionary, Harper & Row, 1983, ISBN
0-06-091082-8.
BOGOSITY - the degree to which something is bogus. See autobogophobia, a fear of becoming bogotified.
Dave Thomas, Spicy Chicken Sandwich, Fresh Every Day, 2000; 213 G 410
Cal.
One of the other Daves. Good cook, we dont know about his programming.
Sun Tzu, James Clavell, The Art of War, Delta, 1999; ISBN: 0385299850.
Life is a battlefield. Plan to win.
Gerald M Weinberg, Quality Software Management, Volume 1, Systems Thinking, Dorset House, 1992; ISBN 0-933963-22-6.
________, Quality Software Management, Volume 2, First-Order Measurement, Dorset House, 1993; ISBN 0-932633-28-5.
________, Quality Software Management, Volume 3, Congruent Action, orset
House, 1994;ISBN 0-932633-24-2 .
________, Quality Software Management, Volume 4, Anticipating Change,
Dorset House, 1997; ISBN 0-932633-32-3 .Rebecca Wirfs-Brock, Brian Wilkerson, and Lauren Wiener, Designing Object-Oriented Software, Prentice Hall,
1990; ISBN 0136298257.
286
________, The Psychology of Computer Programming, Dorset House Publishing, 1998, ISBN0-9263-42-0.
This is the silver anniversary edition! Way back in 71, Weinberg made it
clear that programming is a people business, not a technical business. Why
wont Ron ever learn?
________, The Secrets of Consulting, Dorset House Publishing, 1985, ISBN
0-932633-01-3.
Weinberg brings his usual good humor and good advice together in this
bookabout the irrational world of consulting. Ron likes to read it in the
evenings after a rough day with a client.
________, Understanding the Professional Programmer, Dorset House, 1998;
ISBN 0-932633-09-9.
Are you a programmer? Weinberg can help you understand why you are the
way you are, and how to be a better one. Hang out with programmers? Read
this book in self-defense.
Garry Willis, Lincoln at Gettysburg, The Words That Remade America, Simon
and Schuster, 1992; ISBN 0671769561.
How those 272 words we memorized in school changed the meaning of the
Constitution. A reminder that a powerful message simply expressed can
change the world
Edward Yourdon, Death March, Prentice Hall, 1997; ISBN 0-13-748310-4.
The most depressing book Chet has ever read, and hewas an Economics
major. Yourdon almost seems to approve of the march, and tries to help people make the best of it. XP is about avoiding the death march. You might
like that better.
Edward Yourdon, Decline and Fall of the American Programmer, Prentice
Hall, 1994; ISBN 013191958X.
Yourdon predicts the end of the world as we know it.
Edward Yourdon, Rise & Resurrection of the American Programmer, Yourdon,
1996; ISBN 013121831X.
Yourdon becomes an optimist
Edward Yourdon and Larry L. Constantine, Structured Design: Fundamentals
of a Discipline of Computer Program and Systems Design, Prentice Hall, 1986;
ISBN 0138544719.
287
Good material on the use of coupling and cohesion. Dated now, in these
days of objects.
William Zinsser, On Writing Well, HarperCollins, 1998; ISBN 0-06-273523-3.
We hesitate to list books on writing here. Weve tried to follow this good
advice. To the extent that we have fallen short, we blame these other books
for being unclear or difficult. And, of course, its Chets fault anyway.
288