20 November 2011

Essential Test-Driven Development: Just Say No to Unit-Testing


Wait...Is He Kidding?

A while back I was working with a large client to plan their Agile training curriculum for teams across the country. They wanted to have ready a few courses on Agile development practices, and I recommended my Essential TDD course as a starting-point.  The head of the program said, "Let's not train them on anything that advanced.  Let's start with a unit-testing course."

I answered, "I find it easier to train and coach people on good unit-testing practices through the practice of Test-Driven Development. TDD makes unit-testing easier: Easier to do right, and easier to do in time to make a difference."

Unit-testing, as a stand-alone practice, is frustrating and dull.  The fun work of designing the solution and writing the code is over, and now we must prove that we did it right.  Usually, this means we have to re-read our own code, remember what it's supposed to do, and retrofit unit-tests onto it. The tests we write after the fact are often difficult to write. Often, they give us bad news (that would have been more helpful sooner). Plus our own fallible human brains will often fall back on justifications for why any failing test is wrong rather than an indicator of a mistake (i.e., Confirmation Bias).

Many developers find Test-Driven Development to be easier, more enjoyable, more effective, and more logical.  For me, it was like discovering that I'd been walking on my hands since graduating from college: Yeah, after 10 years I was pretty good at painstakingly writing simple, quality code without unit-tests, but once I got used to the "weirdness" of TDD, I saw how my old ways had limited my creativity, productivity, and understanding. I was back on my feet.

Just Like Science, Only Totally Different

Software Developers are natural problem-solvers.  This can be to their detriment. When we write software "on our hands" we mentally note the problem, then select the most interesting solution of the half-dozen that pop instantly into our heads. "That smells like a Composite Pattern.  Yeah!  I'll implement a Composite here." Yep, I used to design up-front.  Only it turned out not to be a Composite, and I wrote too much prematurely-generalized code, giving my product capabilities that no one asked for, yet someone paid for.

I also had extra code to maintain. Every time I added new behavior to "my" code, I had to carefully ponder the effects of my changes on the myriad intricacies of my existing beautiful design.  The more the software grew, the more the complexity problems grew, and the greater chances I would introduce a defect.  Walking on one's hands is a cool trick, sure. It's just not the most professional strategy.

Fortunately, in 1998, XP Coach extraordinaire Fred George came to visit our team, and turned my world upside-down.

In college (1984) I started out as a physics major, and thrived in all environments where scientific experimentation and discovery were the norm. Creating a hypothesis and designing experiments is somewhat akin to writing a unit-test first: State the problem first, then use that to prove the solution. Then refine the problem/solution pair through Merciless Refactoring. When I realized this, I was hooked.  TDD feels more like scientific investigation, and less like hacking.

Science isn't the perfect metaphor:  After all, you can't make a false hypothesis true by tweaking the Universe.  But you can make a test pass by making small changes to the code (Bob Martin calls them Transformations).

And It Works!

The results of the case studies indicate that the pre-release defect density of the four products decreased between 40% and 90% relative to similar projects that did not use the TDD practice. Subjectively, the teams experienced a 15–35% increase in initial development time after adopting TDD. 
-- Nagappan et al, © Springer Science + Business Media, LLC 2008

I used to deliver TDD training at Microsoft for Net Objectives, and I recall talking to two attendees from different teams who, while working on the course labs together, had discovered through conversation that they were assigned to very similar products.  Microsoft is one of the only organizations large enough to do a good study of similar-sized projects, with teams who have the freedom to choose aspects of their methodology.  Up until this study, most of our evidence of TDD's efficacy was either academic or anecdotal.

A few things I'd like to point out from the IBM/Microsoft study quoted above:

First, 40-90% decrease in defect density? Um...wow! (Need I say more?)

Secondly, note that there is a cost associated with adopting the TDD discipline.  This should not come as a surprise: TANSTAAFL, y'know.  Worst case, you take a 35% hit in development time, and reduce defect density by 40%.  Remember what defects mean to us:  Time spent debugging, reworking, and re-testing.  Defects, a form of technical debt, are expensive!  I'll take the subjective 35% initial hit to avoid incurring that debt.

Thirdly, I'd like to focus on that one word: Initial. Any discipline requires time in order to develop a level of comfort, and to see early benefits. Disciplines are, in fact, painful to adopt, and TDD is no exception.  "...Twice as much code...!" developers cry. "No!" I tell them, "Closer to three times the code!" Also, on any program (green-field or existing), you will wonder "Where do I start?" It takes time before the ubiquitous, domain-specific language starts to solidify, and writing the next test becomes effortless.

Fortunately, it really doesn't take that long to see the benefits.  One developer on a team that I trained this summer reported back to me after about a month: "I thought it was stupid.  I'd write the simplest, stupidest little test--yes, first!--even though I knew the implementation was code I could write in my sleep. I had to focus on not falling back on old habits, even though I would occasionally curse your name.  Then, barely two weeks later, one of those stupid-simple tests was failing, in an area of the code that (I thought) I wasn't even touching! That one stupid test saved my bacon.  It was a simple mistake, and if I had checked it in, I could have messed up some very important customers..." His company's customers are legal firms. Like the conference T-shirt says, "TDD Saves!"

I've experienced a number of first-person events where the safety-net of comprehensive unit-tests plus the flexibility and maintainability provided through Merciless Refactoring resulted in astounding payoffs.  In no less than three cases (on two disparate programs), a simple "user story" contained what most teams would call "major architectural changes."  In each case, we were done in less than a week.  I had never experienced these extremely short cycle-times until I worked with teams who embraced TDD.  (I will share these first-person stories in a future blog post.)

Of course, these benefits could perhaps be obtained by simply having a comprehensive suite of unit-tests, so how is TDD better than unit-testing?

Nutrients-First

When I was a kid, I hated eating my vegetables.  My Mom would insist that I couldn't leave the table, or have dessert (if there was any) until I had consumed all those overcooked nuggets of yuck.  I finally learned a trick (no, not feeding them to the dog when Mom wasn't looking - that was my siblings' trick! ;-). I discovered two very important things about vegetables:  They taste better when they're hot, and they taste a lot better when you're hungry.  The trick:  Eat your veggies first!

TDD is like that:  Write the test first. It's healthier.

We (1) describe the expected interfaces and outcomes, (2) confirm that we've asked for something new and unique, then (3) make the code meet the challenge.  The next step, not to be skipped: (4) we clean up the design through refactoring, in preparation for the next tiny step towards the delivery of value.

Once developers grasp why we're writing a single unit-test and watching it fail before we write the code that makes it pass, they eventually cannot resist this mode of thinking. When you write code Test-First, you cannot write untestable code. When you write Test-First, you cannot miss a test; you cannot forget to cover a behavior with tests.  When the test does pass, you're likely done with that test for the rest of time, but it serves as a tiny bit of "executable specification," and it serves as a tiny investment in the future.

The alternate route, adding unit-tests to already-written code, often invokes our "Confirmation Bias":  I will have a nearly subconscious tendency to trust the code more than the tests, and I may tweak a test to match what the code is already doing.


Backups are Free. Restores? Now Those Will Cost You!

I recall just such a confirmation-bias disaster.   In the mid-90's, our Enterprise Backup software's UNIX ports had a chunk of code based on "tar," the UNIX tape-archival command.  On restore, tar would mask out the super-user execution bit. I recall seeing this code (hadn't written it...the architect had lifted it from tar), and assumed that a smart, security-minded thing to do in tar was likely a smart thing for our product, too. Except that our product ran as root anyway, and was expected to restore a whole system to a bootable state.

Oops!  The architect, executive developer, and UNIX developer (me), had all unknowingly conspired to ruin a customer's day ("further ruin" since the customer was trying to restore the root volume on a large server...).  All for want of a clear test scenario prior to the development of this code. All the test scripts we had written around this functionality assumed that the code (and the architect) was right.

How human of us, to assert only that we couldn't have possibly made a mistake. That would be like designing a flawed experiment to prove a pet theory.  You're hurting yourself. You're jeopardizing your career. You're walking hot pavement on your hands. Stop that!

04 February 2011

Go Home Already!

Yesterday morning I decided I needed a break. Not that life had been excessively stressful recently (quite the contrary!), but sometimes you just need to step back, take stock of your surroundings, and move forward again based on a broader perspective. So this wasn't the kind of break where I set work aside, completely, but rather a reassessment of circumstances, and of the choices that are before me.

This reassessment was refreshing, and left me with some energy to write about more of these Agile practices that foster creativity and sustainability.

Slack

Definitions of "slack," and related practices, abound. To me, "slack" means not allocating 100% of the team's time. The team commits to a realistic amount of work, rather than falling for the "planning fallacy" that everything will go according to a rigorous plan.

Teams who don't plan out 100% of their iteration tend to provide more value. This may seem paradoxical, until you consider human nature: If people go into a sprint (a.k.a. iteration) sensing that they are committed to 100% capacity, they start the sprint...sprinting! They are stressed from day 1, and will lose enthusiasm for the work long before the end of the iteration.

Related Practices

Velocity:
Team velocity, measured by "yesterday's weather," can help. If the team tends to do 12 points in a sprint, we schedule 12 points. Velocity--when it's not constantly debated, gamed, or artificially increased--already takes many unforeseen difficulties into account.

Leave Room on the Plate: I've seen teams who set "stretch goals" or add "low priority" stories to the trailing end of the iteration plan. If trust is strong, this can work, but it could lead to overcommitment and disappointment. Instead, I suggest allowing the team to pull small, high-priority stories in at the end of the sprint, if there's time left.

Of course, all other stories must first be "done done." Is there any further testing needed? User documentation to alter? If so, there is still work to be done, and the team should not pull in more work yet.

You know the phrase "too much on my plate"? Be sure you're not asking the team to "super-size" their iteration plan.

Creative Time: Some teams set aside actual "slack time." During this time, the team may:
  • Explore a new technology that would help improve flow later.
  • Refactor that old area of code that bothers or worries us. Perhaps it doesn't need to change very often (else we'd refactor prior to expanding its responsibilities), but we just have some energy and desire to clean it up now.
  • Brainstorm on some upcoming technical challenge.
  • Run a "spike" or experiment.
I've worked with two or three teams who adopted this practice, and they used guidelines like these:
  • Thursday afternoon was set aside for "play."
  • Each person could use the time to explore some area that was of interest, and that had potentially positive effects on career skills or the team's well-being.
  • The team was asked not to work on stories from the iteration. If they had, this would throw off the velocity and thus erode this practice over time.
  • Examples of acceptable activities: Spikes (timeboxed experiments). Refactoring away some technical debt. Trying out a new development or testing tool. Holding an extended brown-bag to talk about Design Patterns. Anything that didn't break the previous guidelines.
  • We asked the team to describe how they had used their slack time at the next stand-up meeting, and "it wasn't very productive" was an acceptable answer, with no stigma attached.
  • Full-time employees could even simply play video games or surf the web if (a) they sincerely needed the down-time and (b) they gave a report at the Friday stand-up (and "I played Dragon Age and got my mage to level 17" was perfectly acceptable).
External coaches weren't to play games (obviously!), but we derived plenty of joy and relaxation from refactoring the snot out of some bit of nasty code. Once, frustrated with some quirks of our old Java IDE (note: It was neither Eclipse nor IDEA), we evaluated IDEs and recommended (either Eclipse or IDEA) the next day. The team agreed to use the new IDE in the next iteration.

I suggest Thursday afternoons rather than Friday afternoons, because on Friday afternoons people will naturally just escape after lunch for the weekend, and little team value will be obtained.

Sustainable Pace and Energized Work

Different people have different amounts of daily sustainable energy for doing certain parts of their jobs. It often appears that younger developers have more energy to work long hours on a problem. I've since realized that what most knowledge-workers of any age tend to do is to push themselves beyond their own rational limits, into an "irrational loop." They're too wrapped up in a problem to realize that they're tired and hungry, so they keep pushing on that problem. In the irrational loop, they become more and more frustrated, and are prone to make simple mistakes that cause the solution to elude them further, resulting in more time spent looking for a solution.

I sometimes quip that most bugs are written in the last two hours of a 12-hour day. It's probably not accurate as stated, but it gets the point across: Work hard while you have the energy, then stop.


I cannot count the number of times over my 25 years when I've had to be the one to say "Y'know, this problem will wait for us until tomorrow morning." In fact, it's now one of the most fulfilling parts of my job as coach to say "You're stuck? Roll back to the last green bar [i.e., all tests passing] in your local repository, go get some food, some rest, and some time with your families. Go home!" Nearly always, the next day someone walks in having realized what the roadblock was, and with a good solution rattling around in her skull.

There's another benefit: People will sometimes avoid going home because there's even worse stress waiting for them there. But those troubles won't fix themselves, while we hide at the office answering megabytes of e-mail. Letting people have the time to spend with families, on hobbies, and on a full night's sleep pays off almost immediately: Fewer sick days, fewer chronic family issues, higher retention, and alert, relaxed teammates!

In my own experience, I know I can teach my courses with four hours of sleep and a double-shot espresso, if I have to. But I'm effectively on autopilot, playing back the recorded messages in my brain when asked a familiar question. Instead, I prefer a good dose of actual sleep, and no caffeine: I'm more focused and more in tune with the needs of the attendees.

Related Practices

Go Home: Once you know approximately where your limits are, set a time when you plan to go home, and stick to it. Let colleagues know when you're starting to run down, and that you've got about an hour left of productivity in the office. Schedule time for yourself at the end of the day: A yoga class, dinner with the spouse, or just a "go home" reminder on your calendar. When asked if you can attend that 6:30pm meeting, say "No."

One Failing Test: For TDD or XP teams, this is a favorite for lunch breaks or at the end of the day. Leave your (small amount of) uncommitted changes on your dev machine with a single failing unit test to mark where you were. It will take no time at all to figure out where you left off. Much less context switching! Of course, "all-green and committed" is an alternative, but there's nothing quite as concrete as a single (uncommitted!) failing test to get you back into the Zone.

We appreciated this practice so much, we'd start a new task and write the first failing test with only a few minutes left in the day.

Continuous Learning

On a day-to-day basis, people are energized by intrinsic motivators such as interesting, valuable work; pride in quality work; and interesting learning experiences. This does not have to be limited to a yearly trek to a trade conference. Those are great, but if they're the team's only source of fresh mental stimulation, all those spongy brains are going to be surviving on minimal subsistence the other 51 weeks of the year.

Related Practices

Sharpen the Knives: You've heard the old adage about the lumberjack who--in order to cut a tree in an hour--will take 45 minutes to sharpen the saw?

This old analogy really needs updating: Not many of us are all that familiar with the logging industry. Right now, reality cooking shows (Top Chef, Iron Chef, ...) are hot, and I've just learned the right way to sharpen cooking knives (one way for me to contribute in the kitchen, besides cleaning it).

So, why do chefs sharpen their knives? Because they can go faster, work more accurately, and create higher quality. We wouldn't tell a chef to "just keep cooking! Go, go, go! Never mind quality or technique or safety..." Would we?

Most teams need to "slow down to speed up" using "Slack," and this practice takes slack one step further: We improve throughput of value by allowing the team the time and authority to learn an effective new skill.

Pair Programming: Two people collaborate on critical efforts, so teammates constantly learn from each other. This learning is not the result of a teacher-student or master-apprentice relationship: Peers can share a variety of things, including efficient tools and techniques, domain knowledge, product knowledge, and appreciation for the skills and responsibilities of other teammates.

Summary

"Measure twice, cut once."

"Sharpen the saw."

"Slow down to speed up."

"It's a marathon, not a sprint."
In all endeavors, at all of life's stages, the best action to take is often counter-intuitive. When you feel that old chaotic wind spinning around you, step back, get more of the big picture, and try out one of these practices, or one of your own invention. They are all essentially the same: You are taking the time necessary to complete your task with a high degree of quality, integrity, and craftsmanship; and without ruining your health.

Okay, I'm outta here...!

03 January 2011

Gentle Discipline: Making Agile Happen in the New Year

Update #1 for 2013:  When this was first posted, I had a few people point out that I was talking about self-discipline.  True enough!  I'm not sure I can conceive of any other form of successful discipline.  It's possible that I'm biased because I'm an Agile Coach; or--more likely--that I've become an Agile Coach because of this bias.  The "User-Friendly Discipline" is my name for an observed phenomenon, not for something I thought up. It is the only form of real discipline I've ever known to work, in my own life as well as the lives of those I've encountered, over nearly five decades, and on three continents.  The assumption that you can force other people to do something as a discipline is, to me, disproven by my observations of successful disciplines (as described below). YMMV, but I doubt it. -- Rob

It's 03 January 2011, and I'm going to wait one more day before going to the gym. If you've ever had a gym membership, you know exactly why: Right now, every gym is a zoo of humanity. Right now, hundreds of new people join the gym and try so very hard to live up to their New Year's Resolutions.

But, as the regulars and the staff are aware, most of those newcomers eventually give up and stop coming. Though I'll be happy to have things back to normal, I always feel a little sad for the people who weren't able to establish an ongoing discipline.

The D Word
In my courses, I often ask people what comes to mind when they hear the word "discipline." Images arise of strict teachers with rulers, or boot camp drill sergeants. The word seems to imply rigorous, strenuous rules, extra effort, and--above all else--suffering.

Many people stop going to the gym because they start out too intense. Often their fit (and younger) personal trainer has constructed a regimen suitable for a Marine; or they just push too hard the first day, and still can't lift their arms above their head a week later. Or they tried to dedicate all their free time to this one endeavor, and life (laundry, house-cleaning, overtime, friends) intrudes; or at least provides an excuse.

Discipline: The User-Friendly Definition

The way to establish a consistent, painless discipline is embedded in my formulation of the "acceptance criteria" for a discipline.
  1. A discipline is a habit...
  2. ...that you come to rely on, even during difficult times...
  3. ...because you know that it benefits you, personally.
Let's examine each of these further, and I'll make some suggestions on how to implement this.

A Habit...
A habit is something we do almost unconsciously, and frequently. There are good habits as well as bad. Think about the numerous habitual disciplines you've already established in your daily routine before going to work. Most people shower, put on clothes, and brush their teeth. If you think back, you had to be taught all of these, and some of us probably put up a fuss over these disciplines as children. Do they still seem painful? Would you give them up?

I recall learning (perhaps many decades ago) that to establish a habit, psychologists suggested we repeat the behavior for about 30 days. Whether this rule of thumb is still canon or not, I've found that we must remind ourselves, and perform the activity, repeatedly until we know we can discard the reminder.

A sticky-note on your mirror could remind you to floss. A daily alarm on your calendar software could remind you of the stand-up meeting. A big, visible chart graphing the number of unit-tests checked in to the repository could encourage the team to write tests (first! ;-).

...We Rely On...

For a practice to become a stable discipline, enough people on the team (it could be a team of one) have to be doing it habitually so that it will not die out due to some minor random event (e.g., when two new developers are added, or while three people are out with the flu).

A Tale of Two Teams

I've observed at least two Extreme Programming (XP) teams as they discovered they needed to rush out a release. One organization decided at the last moment to show the product at a trade show. On another team, there was a customer anxious for an early Beta release, and willing to pay.

The reaction of these teams suggested their levels of discipline with various practices. The less-experienced team gave up TDD, pair-programming, refactoring, code-reviews, object-oriented goodness, all manner of sanity; and just cranked something out. The product failed to "wow" anyone, to say the least.

The other team acknowledged the crunch, took a little time to re-prioritize and break down the backlog, then sat down in pairs and practiced their testing and engineering disciplines as though nothing untoward had happened. Their release may have been short on bells and whistles, but it was also very short on defects. (And they sold many licenses and the VCs lived happily ever after, The End. There be Agile Dragons, remember?)

A key lesson from these events was that a discipline isn't ever something we think is "a great idea, in an ideal world, but we're too busy right now in the real world, so could you bug us about it later?" You have to know its true value, in your bones.

Frequency Over Intensity
Lather, Rinse, Repeat. Always Repeat.
-- Homer J. Simpson
To get there, it's important that you repeat the activity rather consistently before a crisis occurs, and through some minor daily crises. Even when, especially when, it's painful to do so.

Here's one of the user-friendly parts: Early on, frequency is more important than intensity. You can tone down the practice until it becomes a habit.

An example for the resolute exerciser: If your muscles are sore, just go do your cardio. (If your regimen is purely cardio, then go play lightly on the weight equipment.) Just go have fun with it.

An example for the blossoming meditator: No time to practice? Sit down and breathe slowly and deeply three times, then get up and go to work. (And try not to curse at traffic lights, or other drivers. ;-)

For the Agile team participant: Try a new practice wholeheartedly for a month (only one to four iterations). You know you can ask the team to reexamine and tweak the practice at every retrospective; so don't evade, grouse over, or sabotage the team's efforts. Do it as though you believed in it, and that your project or career depended on doing it well.  (It does.)

My friend Bob Hartman once helped establish a team's pair-programming discipline by asking the team to pair up whenever they were fixing a bug. "If one person broke it, why do you think one person can fix it?"

...Because It Benefits Us
We won't even attempt a new discipline without some indicator that it's valuable. We observe people who are healthy and happy, and they exercise in some way (among other things). We observe teams who produce high-quality software, and they're using fast, automated testing (among other things). We want that!

At the team or organizational level, we want fewer defects, faster time-to-market, more profit!

Weigh Costs, Too

If the individual, team, or organization picks up a new practice, the benefits are probably well-documented. What may not be clear from the literature are the costs. Both have to be considered in order to select the right set of practices for the organization (or organism).

Unfortunately, the costs--or aches and pains--are always more intense when you first start out. So, there's frequently early resistance ("emotional re-evaluation"), which could stifle the burgeoning discipline.

It's Personal

The biggest hurdle hiding within the acceptance criteria may be even more daunting: In order for it to be a discipline, each participant must have experienced (past tense) at least some small personal benefit from the discipline.

Effective disciplines are not followed out of altruism, nor are they followed because people are getting paid to do it the "right" way. Even Mother Theresa admitted to personal benefit and pleasure in helping others. And I've worked with many large organizations who were paying good salaries to people who didn't really do much: They were mostly trying to stay hidden, and waiting for their pension to kick in.

Even those employees are not very happy in their careers. People need more than a big paycheck to feel happy. What's sad is that many of them don't know this. They think "that's the way things are, and there's no way to change the system."

Every good discipline has something in it for you, the practitioner! The benefits of my sample disciplines (exercise, flossing, meditation) are clearly personal, and entirely obvious, right? ;-)

How about Agile disciplines? "What's in it for me?" Here's just a sampling, regarding some of the most peculiar Agile practices ever devised:

Paired programmers report that they are more confident in their solutions. Their defect-density drops, and they spend far less time in the debugger. They feel that they--even the old-timers--are learning from their peers at an exhilarating rate. They are more comfortable around teammates, and more confident in their discussions with management. They have fewer carpal-tunnel-related complaints. Ultimately, the feel more productive.

Disciplined TDD developers report an uncanny level of confidence in the quality, design, and adaptability of their code. At first the costs seem prohibitive: Extra test code needs to be written; and since the design emerges over time, time is spent continuously refactoring (which is the design mechanism in TDD). But after only a few months, they are able to add new behavior into the system in days, rather than weeks; and they use tests to seek out, isolate, and crush defective scenarios (bugs). They report that they recoup nearly all the time they would otherwise spend in the debugger. (I've had developers tell me that they used to spend half their time debugging. What would you do to recoup almost 4 hours of each day?)

Once people get a taste of these benefits, they have a much easier time continuing the practice, and improving upon the required skills. For them, it has become a real discipline.

Additional Suggestions
Stop Lamenting the Past

If your blueprint for success contains (or implies) "Step 1: Build Time Machine" then you need to rethink your plan.

In order to establish a discipline, you must stop dwelling in the past. You're out of shape? You can't leap into strenuous exercise. You have a million lines of untested code? The optimal path is not to take a year off to cover all that code with characterization tests. Hundreds of severity-one defects? Funding a complete rewrite isn't going to help.

There isn't a single discipline on Earth that involves wishing things were otherwise, or fixing everything that's broken.

Stop Blaming

Never punish or berate yourself or your team for the occasional relapse into those old 2010 days.

Acknowledge the lapse, yes. Perform root-cause analysis and see if you need to jiggle your circumstances to prevent a future relapse.

Let me ease your concerns here and now by assuring you that lapses will happen. So, now that you already know, you won't have to argue with yourself about perfection and responsibility. With each lapse, you simply have to re-commit to practicing now and in the future. (And, yes, you will have to pay your personal trainer for the missed session.)

But you can't try to make up for it. One of the worst mistakes I see in the gym is working out twice as long after missing a session, or after eating too many holiday treats. That path leads to further discouraging circumstances. Sure, if there's a minor mistake that can be corrected (e.g., by adding unit-tests around new, untested code), then do it. That's correcting a mistake. "Correcting" a relapse involves extra time practicing the discipline, and that invariably eats into the time needed by some other practice. Tomorrow is another day.

Does this conflict with my suggestion to focus on frequency over intensity? No, because I was not suggesting that if you go a day without (flossing, meditating, a daily stand-up meeting) that you have to start the 30-day clock all over again in order to build the habit. When you fall down, get up, dust yourself off, and get back on the bike.

Stop the Excuses

Don't over-plan your efforts towards a new discipline. A complex plan is full of opportunities for reversal. What we're really doing when we over-think the practice is creating a mental model of our lives where the practice is ultimately not worth the effort.

That is, we invent our own cosmic excuses. This takes a certain level of cleverness. If we are to try something that doesn't come with a guarantee of instant gratification, this cleverness must be tempered with courage.

You're intelligent. You're courageous. What are you planning to try this year? Add a comment and share your experiences.

Update #2 for 2013: I've noticed another impediment to creating a healthy new discipline:  Embarrassment, or peer pressure. "Why must you _____?!" people will ask (or imply), incredulously. I have a number of very old habits that a few people have (openly and vocally) suggested were professionally lazy: Exercising three times per week, meditating for 1/2 hour per day, and getting eight hours of sleep on most nights.  I don't tell you about these now to be self-aggrandizing (or self-effacing) but as factual examples:  For me, they are so routine that when I have to drop one, I become cranky, and much less effective at work. They are all wonderful, productive, professionally supportive, healthy habits. But disciplines that are counter to prevailing culture will meet with resistance.  If you can use your own facts and experiences, you will be able to politely and clearly convey the benefits to those who are skeptical. That's how culture is slowly changed. Have courage!

Have a happy and prosperous New Year!

28 October 2010

I Have Written Bug-Free Code Without TDD

There's an excellent blog post by Felix Geisendörfer which gives his experience report on using TDD. Kent Beck tweeted about it, so it's hopefully "going viral" right now. Read it here.

Reading his post, and some of the comments afterwards (when will I learn?!), got me to thinking about my own experiences with TDD, and I decided to share two of my own stories.

Once Upon a Time

I used to write bug-free software without TDD! (Look at me: I am so smart...)

My boss and I would play this game called "Who Wrote the Bug?" in which he would claim that a bug was in my code, and I would come back (after painstakingly debugging the whole product) and point out where it was in his code. (Hmmm...who was smarter?)

Humility Sets In

The software I was writing was a protocol stack that needed to convert between 8-bit and 9-bit bytes, or 16-bit and 36-bit words. I used the command-line/printf approach (System.out.println for the Java readers; Console.WriteLine for C# readers) to test stuff. The debugger, COFF, was okay, but testing through a debugger is such a pain.

If you haven't figured it out from the clues I've dropped, this was over 20 years ago. In retrospect, this was pretty tame stuff. I could keep track of what was going on in my head.

One can assume that software projects these days are more complex. Perhaps too complex for one person to keep track of all the little moving parts. It's enough for the team to have a grasp of the overall concepts, goals, and metaphors.

I would argue that even on a team with only three or four developers, eventually they're going to bump into each other's changes. They need a suite of microtests in order to maintain quality code.

The test frameworks like JUnit, NUnit, and RSpec essentially give you a way to let the computer check the "printf" output (figuratively speaking) for you. You record your assumptions, rather than manually checking them each time, and you can let those assumptions grow upon each other. You record them separately, rather than interspersing the following infamous abomination:
#ifdef DEBUG
printf("foo=%s", foo);
#endif

Two Years of Investment

In 2002 I worked on a team of four J2EE developers on a life-critical (i.e., "You break it, someone may die") application. After two years, we had built some pretty sophisticated reports and heuristics that helped hospitals determine who was most likely to survive an organ transplant.

We had over 10,000 tests. They all ran in about 12 minutes.

Imagine: All aspects of a complex, life-critical, team-built application could be thoroughly checked in 12 minutes. We could (we did) bring in someone new, and essentially say "today we will make whatever changes we need, even mere hours before the next release, as long as we run all the tests and see a 100% pass-rate!"

Twelve minutes, and we knew we hadn't broken any of our careful, 8-(plus-)person-year investment.

Rise to the Occasion

If you're sitting alone in your basement writing a game to sell to a VC, you may not care if it's maintainable. By all means, please continue using only manual testing techniques to verify your app. I'm not being snarky: This may be the optimal win-win approach for you and the VC. (The team that eventually maintains your app will curse your name and throw darts at your picture, but do you care?)

On the other hand, if you're part of a team, writing mission-critical software for a large or complex domain, and it needs to get beyond version 1.0; then please: Make sure you can always test everything, and quickly. TDD is the best--the only--way the industry has invented so far for doing this.

Anything else would be unprofessional.

28 August 2009

There Be Agile Dragons!

At recent conferences such as Agile 2009 and SQE's Agile Development Practices conferences in Vegas and Orlando, I've been running into more and more actual decision-makers. This is exciting, because it's one more indicator that Agile is "crossing the chasm" into regular, large-scale corporate use.

These decision-makers usually want to know, "Will this Agile stuff really help, or is it just another process fad?"

I always converse enthusiastically with people interested in "going Agile," but I no longer limit myself to "Agile" methods. Often, I'll avoid even using the term (though I have no plans to change the name of my company just yet...).

I tell them I'm interested in helping teams examine and alter their development processes by identifying bottlenecks, looking for root-causes, finding ways to ease those constraints, and delivering valuable software.

XP practices, Agile management, Lean leadership, and an overall "Theory of Constraints" approach; all these should be in the software-dependent organization's toolbox. What we call "Agile" is a subset that applies to a variety of constraints, but not always to the limiting constraint.

Dramatis Personae
Over the decades, I have picked up techniques to uncover people's key concerns. I can talk until I lose my voice; describe the latest findings, and pause to listen as they come to their own conclusions.

Decision-makers usually have a healthy dose of skepticism towards new (or seemingly new) techniques. They pick things up somewhere between the early adopters and the late adopters. It may even be a corporate survival trait. Skeptics are always fun to talk to.

But then there are the naysayers, who seem to believe their team cannot do anything right without constant oversight and carrot-and-stick incentives. Naysayers will listen, but then they simply reiterate their position, and will try to keep you in the conversation until you concede (whether or not you realized you were in a debate).

I think I know why: These are leaders burned by some past failure, and are avoiding failure by avoiding change. They will try to build a mental model of some new thing (Agile), and then run virtual scenarios in their minds, rather than committing themselves and others to real risk. Unfortunately for them, their mental model cannot be completed through mere conversation.

To them I now say: "Meet The Dragon."

The Boy and the Dragon

There's a story (very old, but I can't find a handy reference, so I'll bring it up-to-date) about a boy who loved dragons. He drew pictures of dragons, wrote poems and stories of dragons, and read books about dragons. He even dressed as a dragon for Hallowe'en, and his Twitter-name had "dragon" in it (there, now the story is updated).

One day a great, wise dragon heard about the boy, and thought that she would delight the boy by visiting him at his home. "Imagine," she thought, "how excited he will be to finally meet a real dragon!"

She appeared one night in his room and began to speak...

The boy saw the dragon in his room and was so terrified, he could neither move nor reply. His eyes were wide, his heart pounded, and he was in such a state of shock that he could not even scream. The terror was so great that he died of fright right there and then!

(Okay, okay, the dragon gives him CPR and he lives. In fact, the dragon, let's call her "Puff,"and the boy--I think his name was "Jackie Paper"--become fast friends. Better? Sheesh! Remember the good old days when children's stories used to be truly scary? ;-)

DM: Dear @AgileCoach, Do Dragons Really Exist?

Yep. There are many successful Agile teams around, actually doing Agile stuff because they want to; because they produce high-quality, high-value software quickly; because they enjoy working in an environment that encourages them to learn and to succeed; and because it seems the most professional way that we know of--so far--to build real software.

I have met many real Agile dragons of all shapes and sizes. I have assisted dozens (perhaps over 100) of transitions, and many of those have adopted Agile far enough to leap beyond mediocrity. I have been a contributing team member (long-term, full-time coach/TDD developer/project manager) on at least four exceptionally successful teams: Small teams, larger teams, applications handling millions of dollars, and one life-critical ("you break it, someone may die") application.

"I'm Not Your Life-Coach, But Since You Asked..."
Do you have a friend who wants to be a great actor, a supreme-court judge, an astronaut? (Not someone simply greedy for fame and fortune, but a sincere, interested, even talented individual.) How many of his friends are supportive, but secretly think he's foolish? Do they encourage him with vaguely positive platitudes, yet privately think he should take that accounting job at his father's firm?

I would tell this person (if asked): "The odds are against you, and you may have to 'settle' for less than a bullseye, but there are indeed famous actors, supreme-court judges, and astronauts in this world. Who is to say you won't be one of them? Seeing is believing, so [quit telling me about your fantasies and] go find one to talk to!"

But assembling an exceptional software team is so much easier. You're not competing for a finite number of roles/seats/launches. There are plenty of problems that software can solve, that it hasn't. You don't have to have only the best programmers. You don't have to have Steve Jobs as the Product Champion and Ken Schwaber as the coach.

I'll give the aspiring actor and the aspiring Agile team the same advice: Identify your weaknesses, work to reduce their impact. Identify your strengths, and leverage them. And don't be discouraged by an apparent lack of progress. You may never get to where you though you wanted to be, but you will be much happier with the results than if you just kept doing what you were doing. You'll "get what you need" (Mick Jagger, of course).

Visit the Dragon's Lair

I think Pivotal Labs in San Francisco will give you a brief tour, and will describe what they're doing. I know that Menlo Innovations in Ann Arbor will give a two-hour tour, and in fact their tours are so popular that they've published a book and posted video on the web for those who cannot make it out to Ann Arbor. Another in the Bay Area, I'm told, is Sarah Allen's Blazing Cloud.

A few Wise Dragons to choose from. At each of these places, you can watch real software being made using Agile management and development techniques.

And rather than falling for the cynical belief that it can never work at your shop, let me bring in my executive coaches, Lean/Theory-of-Constraints experts, and Agile Mentors (me and others), and we'll help you reveal the Wise Dragon lurking within your teams.

You don't have to believe, you just have to get over the shock.

03 August 2009

Innovation isn't Dead, but Remember to Feed It

In mid-July, I attended a 20-year college reunion of close friends who graduated mostly from Northern Arizona University's Computer Science/Engineering college. We call these, affectionately, "Geek Reunions." We get together about every five years in Flagstaff to reminisce, eat at our favorite college restaurants (Alpine Pizza and Macy's Coffee House, both still open after decades of abuse), and to marvel at the wonders of computer science.

Except that, in twenty years, what do we have? Some cool web-apps (the Internet already existed) like amazon.com and Google Maps. We have the iPhone, and we have [insert your favorite high-tech whatzit here rather than flaming me for forgetting it]. And that's about it. (Okay, to be fair, here are others that I can't imagine living without, though we did alright without them in the 80's: Microwave ovens, cell phones, GPS devices, hybrid engines, LED flashlights, organic produce, PDF documents and ubiquitous e-mail [together negating FAX machines, which were always an insult to human intelligence], flat-screen TVs, sticky-notes, much-improved solar cells...)

I haven't read the book Where's My Jetpack? yet, because I think it could trigger a panic attack. But I heard the author on NPR describe various inventions and leaps of human progress (both far-out and practical) that were predicted to exist, but still don't. Some that I lament: Bullet-trains crisscrossing the nation, Moon Base Alpha, fusion power, a Martian colony, a world-wide food program, world peace, the elimination of cash (or at least those darn noisy/heavy/barbaric coins), ubiquitous personal digital signature authentication (eliminating check-writing, contract-signing, and--sadly--the USPS), solar-power collection farms dotting the nation...

Among the participants at this reunion were at least four previous NAU Association of Computing Machinery student-chapter presidents, including myself. The current NAU ACM President, Leah Shanker (her blog), offered to give us our usual nostalgic tour of the newly remodeled Engineering building on South Campus. We noted, too, that the Business building had undergone remodeling, and was now much taller...blocking the view of the San Francisco Peaks from every vantage point in the EGR building and on the popular grassy "quad" below it.

There has always been a friendly rivalry between the Computer Science/Engineering program and the Business College's Computer Information Systems program. But this was an affront to nature! We immediately discussed ways to regain a view of the Peaks: From mirrors to wormholes to particle accelerators to bulldozers...

Where Have All The Nerds Gone?

Apparently the NAU student chapter of the ACM had fallen into obscurity after our network of friends had left. In fact, the whole computer science program had suffered an extreme drop in enrollment.

When I graduated, the artificial bubble known as "Star Wars" or SDI (Strategic Defense Initiative) was just collapsing. Some of us had moved to various cities and signed one-year leases, only to get laid off the next week. (I can't complain. Had I taken a job with Lockheed-Martin or McDonnell-Douglas or Skynet [makers of the T-100], I would likely not be an agile coach now. For me, it was a lesson in turning a bad situation into an opportunity. Of course, it took ten years and 20/20 hindsight...)

For a while (and possibly throughout the dot-COM era?) a CSE degree was not seen as quite as valuable, or as interesting, as a MBA. And, even today, the NAU CSE fourth-year class has only two women enrolled. That's about 1 percent, and far lower than when I was there. Leah is one of the two.

Return of the Nerdi

But there was a very bright side to the visit. Leah and her cadre of mischievous engineers were doing all the things we had done: Going to programming contests, returning with trophies, spending free time in the computer labs, socializing in the labs, working in the labs, falling in love in the labs, hacking campus computers (Leah did it as part of a report on computer security, and the dean had to intervene to keep her out of trouble!), trying to interface computer software with robots, and writing computer games. They were exploring their medium.

I had to ask "so, you're not trying to invent the next killer web app?!" Leah cocked her head skeptically, frowned, and pointed out the window...at the Business building.

"Rob, Aren't You an Agile Business Coach?!"

Of course, business thrives on both technical and business innovation. I see amazon.com as originating from business innovation. Put the whole bookstore (and quite a few other stores) right in front of people, give them a way to rate products for each other (and appeal to their ego at the same time), and tell them about products that they may be interested in (with an all-too-easy one-click purchase option).

It's like a mall crossed with Consumer Reports crossed with a Personal Shopper. Amazon.com takes far too much of my money from me each year, but I get these little packages of joy delivered to my door, even when it's not Christmastime! It's brilliant.

Now amazon.com has made much of its sales engine available to developers via their web-services API. They're using a technical innovation, and that's paying well, too.

If we consider the original web search algorithm, Google was a technical (mathematical, algorithmic, scientific) innovation. I recall wondering how they were going to turn that into a business success...until they came out with those short, text-only, search-related advertisements. That was a clever business innovation, later measured as the most effective use of advertising dollars on the internet.

I knew that Leah's reference to the Business building was her way of doing her part to keep the CSE vs. CIS rivalry alive, and I was encouraged by that. We need both forms of innovation, and keeping them somewhat separated is probably beneficial.

Imagine if the Google founders had waited until they had all the infrastructure ready to make money before enabling search on the Web. Imagine if amazon.com had waited until the advent of standardized web services before launching their site.

I wonder how many companies have failed because they refused to launch until they had the market all tied up in a neat little ball? (Remind me to tell you the sad story of Cymerc.com. They relied on Cysive to build the product, and Cysive was not agile. And now they're both dead.)

Some companies (particularly start-ups) rely mostly on one or the other form of innovation, but most midsized or larger companies these days need to consider how to stimulate both.

Seeds of Innovation

The unbounded, un-purposed exploration that's again happening in my alma mater is a key ingredient to innovation. Whether or not some great invention will appear from the halls of our Universities; this is not my concern. But software development teams need an environment that is similarly conducive to exploration, and perhaps tolerant of a touch of mischief. The mindset of exploration is the driver of innovation, and cannot be forced or coerced, even with bags of money.

I dearly miss Flagstaff, the NAU campus, daily interaction with those friends, and that feeling of exploration. Yet I left the reunion with a happy heart: Software innovation is not dead!

05 May 2009

First Steps Towards Agile

Yesterday I received a note from a fellow NAU alumnus who found me on LinkedIn and asked where to start with a small-team transition to Agile.

Aside: I sent a reply; mostly an unedited stream-of-consciousness, but I thought it was good enough to post here. I'm not sure I'd give the same advice to everyone, but it seemed to make sense for his circumstances as I understand them. I got the sense that he's in need of a do-it-yourself Agile transition, perhaps due to his remote location. (Though I suspect he knows that I'd travel to his particular region of the country without hesitation. I give discounts for certain personally-nostalgic locales! :-)

Feel free to comment with other suggestions. What would be the first two or three steps you would take in his circumstances?

The Letter

I was wondering if you wouldn't mind helping me? I lead a team of developers, analysts and a webmaster...read a lot about agile and think it's potentially a great way to go. How do I even get started?

To date I started doing some small team-ups for projects we have. I have assigned tasks to different team members. I know this isn't agile but up until this time our team developed everything silo'd. They all had their own projects and never worked on someone else's work... So I figured it would be a good start to at least expose them to teaming...

From here I am really not sure what to do nor do I deeply understand the concepts in agile. I have read a ton on the internet but there is nothing like experience to really help.
Effectively, I suggested he start with a retrospective...

My Reply

Hi,

I think I have a great answer for you, but I want to say a few words beforehand so you don't think I'm just handing you more to read.

I was glad to hear that you're getting them used to working together as tiny teams. I suggest that small organizations try to partition the teams by separate code-bases. Products tend to map one-to-one with a code repository, and teams work best when they map one-to-one with a product. People often try to have multiple teams with their hands in one code-base, and they often discover that they're inadvertently impacting each other. If someone can impact your team, that someone is effectively on your team. But I'm wandering into dangerous territory since I'm not familiar with your set-up.

When a team starts to do things differently, it is difficult to figure out what to do first, or to just jump in with both feet (or head-first, perhaps?). So keep that in mind: Ultimately, you have to decide what's the right first step for change.

It may sound odd, but the first thing that needs to be in place is a mechanism for getting anonymous feedback on how the process changes are being experienced, and what the team's biggest problems truly are. I would start with a "retrospective" meeting. I suggest that teams do this every two weeks. It doesn't have to take more than an hour:

1. Get everyone in a room together and have them write troubles on sticky (Post-It) notes and have them post these stickies randomly on a wall. This gives people the ability to anonymously voice what they see as the biggest pain points. No limit to the amount of troubles.

2. Then have them go up in small groups and rearrange the notes. Not in rows/columns, but in clusters by how closely related the troubles are to each other. Duplicates are very close, similar topics farther, and wild suggestions farther. Let the stickies clump organically, so to speak.

3. Then look for the biggest cluster. Help the team find a way to fix that.

If your team is too small to distinguish a cluster after step 2, replace step 3 by giving each person three stars or colored sticky dots to use to vote for their top three problem areas. We usually require that they cannot vote for the same problem more than once. You'll probably find that they all agree on one or two major problems.

That's one of the first things I would do with your team. But since I don't know what they would come up with as the biggest problem, I can't suggest further action except to go out and obtain a copy of The Art of Agile Development by James Shore and Shane Warden, and read it as though your career depends on it. I worked closely with Jim Shore in 2001 and he knows how to solve problems. Most of what they have recorded there is stuff that we were doing in 2001, and it's still some of the best "agile" advice, all collected in one place.

Lastly, be aware of the two primary reasons why agile projects fail, and how to prevent them:

1. The Product Champion (Scrum "Product Owner" or XP "Customer"), the person who decides what features go in and what features don't, and also chooses which order they go in, must be readily available, willing to work on creating "stories" with enough detail and acceptance criteria so the team knows what is needed, how to test it, and how complex it is (for estimation). And this person must be ready to decide what the top priority detailed stories should be done first. Without this, the project will probably fail. "Agile" is not just a developer's process, it tends to impact the way the organization builds software product.

2. Too few automated tests. I call this the "Agilist's Dilemma" because without tests it becomes obvious to the developers (whether they'll tell you or not) that it's getting harder and harder to change the code to accommodate the next set of stories. At the very least, encourage developers to try Test-Driven Development practices wholeheartedly, right away, for two 2-week iterations. They'll need to learn how to do it right, and with some discipline, to get the full value. Dave Astel's book is good (Test-Driven Development: A Practical Guide), Kent Beck's book is good (Test Driven Development: By Example).

My courses are even better, because you get hands-on experience plus team-specific guidance! I'm also available for coaching, of course.

Serendipity At StarEast

This same question (effectively "What are the first steps?") came up after Lisa Crispin's talk at StarEast today. I like her answer, too. She responded with these two (I'm paraphrasing):

1. Get some Agile training for the team.
2. Talk with managers about how their roles will change, and let them know that the team will need their support and confidence.
Summary

So perhaps I'd alter my list to be:

1. Get some Agile training and/or hire an external coach.
2. Run a retrospective on the current, pre-transition process. Refer to Art of Agile for potential solutions. Try the chosen solution for two weeks. Repeat.

...And include management in both!