Process, People, and Pods


Sunday, 19 August 2007

Keystrokes are NOT Gold

Programmers tend to treat their keystrokes as gold. Perhaps they are driven to counting by project managers. Perhaps their typing skills are atrocious. Regardless, there is a great reluctance to discard code that is wrong. It is wrong because it doesn't work.

A programmer hates being wrong; at least in that respect, a programmer is like every other human being. But in the case of code that doesn't work, there is an almost irrational drive to make it right by adding more code, even if:

  • It means abandoning the design,
  • Coding practices must be abandoned,
  • Complementary changes must be injected into completely irrational areas of system, or
  • Changes to key interfaces must be renegotiated.

Traditional phased process (aka waterfall) tacitly accept and encourage these practices. Testing is done by someone else, usually at some point in the future; this lulls the programmer into thinking the code probably works, and it is someone else's job to validate that assumption. Bugs (the real name of code that doesn't work) maybe fixed by someone else. The chances that I, as the original programmer, might have to make it work are reduced.

But then comes Agile, upsetting this comfortable, lazy acceptance of bad code. Two practices in particular inhibit letting the bad code slide: Test-first development and pair programming.

Test-first has the programmer write the test first, then enough code to make sure it works. Then write another test. The effect of this is that code that doesn't work is immediately recognized. Since all the tests are run before check in (or at least run by automatic continuous integration tools), code that injects a bug somewhere else is detected. But what if the programmer skimps on the tests? What if the boundary conditions are ignored so that personal/team/manager schedule expectations are met?

The second practice, pair programming, makes that more difficult. Now two programmers have to conspire to ignore poor test coverage. But that focuses too much on the negative. Rather with a partner sharing the problem, the second pair of eyes helps identify the marginal cases, and helps find alternative solutions. It becomes almost a mutual quest to solve.

The New Problem of Keystrokes

Agile creates an environment where bugs are rapidly detected. So programmers can be lulled into taking bad code and continuing to change it in the hope that it will (magically) start working. In the ThoughtWorks programmer training course, one objective is to get programmers to overcome their reluctance to throw code away and start over.

The first trick to teach programmers to work in small cycles. In the class, we give a problem to the students (always working in pairs). The students are to write one or more tests and get the tests working. And they have only 15 minutes! Invariably, students start with a test that will prove everything works. When the timer goes off at 15 minutes, they are actually stunned that all the time has passed. They are nowhere near getting it to work. They ask for another 15 minutes, certain that they will finish in that time. Invariably, almost all fail again. Sometimes I give them more time, but it is only to get them to realize that their quest is fruitless. Then you finally have pity on them and show them the secret: write smaller tests. Get something working in the 15 minutes. That "resets" the 15 minute clock.

By the second week of the course, pairs are competing on how many cycles they got done in 15 minutes. They discover that in these tiny steps, they are marching to completing the work with absolute confidence that the solution works when they get there. Indeed, they are stunned when they write that ultimate test of the overall behavior, and it takes just a few lines of code to get it to work. A stark contrast to the frustration they felt when biting off too much.

Now the second trick kicks in. If you can't get the code working quickly, throw it away and start over. In these small cycles, they haven't written that much. The old code worked; the clock is ticking; rather than trying to get the bad code to work, they back up and start over. Code repositories are a huge tool in this; modern tools allow you to revert all the code in a couple of mouse clicks. Now the programmers don't treat that bad code as gold.

The top reasons to discard the code are:

  • It doesn't work. So why are you spending more time creating a bug?
  • If the reason seems to be a muddled design, throw the code away and re-think the design. Kent Beck said, "Code is where design meets the harsh reality of dawn." If the design is bad, the code will scream it out. Listen to the code. So why are you investing more time implementing a bad design?
  • The programmers don't understand the problem yet. Getting stuck can be a sign of a lack of understanding. Step back and discuss the problem some more. So why do you think you will understand the problem better by continuing to write code?

See the trend? Continuing to write code is a waste of time. Discard and start over. It is not gold, but rather .

If you are a programmer, try this out: If the code seems to be going nowhere, throw it out and start again. Let me know how it goes...

23 comments:

SteveJ said...

This is a key component for getting a programmer to actually work a 9-5 workday. At 5pm, if it's not ready to check in, toss it. The code you write tomorrow will be so much better than the crud you've been trying to cobble together, and you won't stay until 9pm trying to make it work.

I also love deleting huge chunks of code that are rendered obsolete when requirements don't quite match reality. At first it feels like you're throwing money away, but as time goes by it becomes much easier to see that you've increased the code's value by decreasing the maintenance burden. Of course most of my team still looks at me strangely, but maybe they write code that makes perfect sense 3 years later. I sure don't.

Fred George said...

Yes! Throw yesterday's code away. You have lost the train of thought. (Great addition!)

I almost always work in pairs on shared workstations. I do get irratated when I sit down, diff the workstation against subversion, and find code dregs! Do I find another workstation? Do I revert?

My other hot-button along these same lines is code that is commented out. I find it -- I delete it. After all, that is what code repositories are for. Much time is wasted studying code that is commented out to see if it was an accident, and should be turned back on. But if all the tests pass without it...

Aslak Hellesøy said...

I love this rule Fred! Let me take quote from your article:

If you can't get the code working quickly throw it away and start over.

(Emphasising/de-emphasising mine).

Folks - your code isn't working unless you have proven it with an automated test.

kiloi said...

puma mens shoes
nike air max ltd
NIKE air shoes
ed hardy clothing ed hardy clothes ed hardy shirtsed hardy clothing ed hardy clothesed hardy shirts

kiloi said...

nike tnEnter the necessary language
translation, up to 200 bytes winter, moves frequently in Chinanike chaussures showing that the deep strategy of the Chinese market. Harvard Business School, tn chaussures according to the relevant survey data show that in recent years the Chinese market three brands, Adidas, Li Ning market share at 21 percent, respectively,

kiloi said...

mens clothing men's sweate, cheap columbia jackets, lacoste sweater, ralph lauren polo shirts,ski clothing. Free Shipping, PayPal Payment. Enjoy your shopping experience on mensclothingstore.UsPuma shoes , Ugg Boots , nike max shoes, NIKE AIR MAX TN ,nike max shoes ,PUMA CHAUSSURES, NIKE SHOX Torch ,puma Ferrari F1 ,PUMA DRIFT CAT

kiloi said...

chaussures puma stores offer you the most popular fashion shoes, including the puma basketpuma puma BanXie and shoes. All the puma product factory direct sale, special processing, create the most inexpensive puma stores.National Weather Service Meteorologist Jason puma CAT said this week's temperatures will mirror seasonable averages of highs around 71 and lows about 42 degrees ...

kiloi said...

ralph Lauren polo shirts , Lacoste Polo Shirts, Burberry Polo Shirts.wholesale Lacoste polo shirts and ralph Lauren polo shirts with great price. clothingol.com offers lot of 10 lacoste polo shirts and lot of 20 cheap polo shirts. clothingol.com offers classic fit polo shirts. polo clothing All our shirts made in original factory.

Anonymous said...

童裝批發

童裝批發

童裝

童裝

酒店喝酒

酒店消費

喝花酒

粉味

酒店經紀



酒店經紀

酒店經紀

酒店經紀茵悅

酒店經紀

酒店經紀

酒店經紀

酒店經紀

酒店經紀


酒店經紀

酒店經紀茵悅

台北酒店經紀

酒店打工

寒假打工

Anonymous said...

And it can be paraphrased?

Edwin said...

Buy Kamagra
Earn Google
Viagra Cialis
Cheap Kamagra
Cheap Viagra
Cheap Cialis
Make Money on Google
M65 Jacket
M65 Field Jacket
Airline Dog Carrier
Airline Dog Carriers
Viagra Cialis
Earn Google
Airline Dog Carrier
Airline Dog Carriers
Airline Approved Dog Carriers
ED Hardy Wholesale
Copy DVD Software
How to Send Fax
14k Yellow Gold
Redneck Costume
14k Gold Heart
Tandem Baby Stroller

Anonymous said...

Bravo, what necessary words..., a remarkable idea


Has found a site with a theme interesting you. Hot Health

Anonymous said...

酒店經紀 酒店打工 酒店工作 酒店上班 酒店兼差 酒店兼職 打工兼差 打工兼職 台北酒店 酒店應徵 禮服酒店 酒店 經紀 打工 兼差

Anonymous said...

To be a upright benign being is to have a philanthropic of openness to the far-out, an gift to trust uncertain things beyond your own manage, that can lead you to be shattered in hugely exceptionally circumstances for which you were not to blame. That says something exceedingly important about the fettle of the principled compulsion: that it is based on a trust in the uncertain and on a willingness to be exposed; it's based on being more like a spy than like a sparkler, something somewhat tenuous, but whose extremely precise beauty is inseparable from that fragility.

Anonymous said...

I've ever liked things like sand clocks, lava lamps, and the like to well-wishing of just spend time staring at it as a cut of catharsis. In a opportunity, it helps me with meditation, to reduce emphasis and just think fro nothing. That's why since I was a kid, in preference to of dolls and cars I've in any case cool more of such pieces like sand clocks, lava lamps, dulcet boxes etc. So I was most delighted when I found the[url=http://www.dealtoworld.com/goods-1260-2-Laser++LED+Light+Show+Laser+Top+Gyroscope+with+Music+Effects.html] 2-Laser + LED Spry Presentation Laser Crown Gyroscope with Music Effects[/url] from DealtoWorld.com answerable to the Toys section. It's like a harmonious belt, a spinning top, and a berate reveal all rolled into one. Which is prodigious diversion! The gyroscope wishes outing representing about a minute. The laser explanation pretension with accompanying music makes this gyroscope a pretty unique bauble that my friends be subjected to also been most amused with.

My dogs are also pretty eccentric nearly the laser gyroscope I got from DealtoWorld.com. They each follow the gyroscope as it spins, although at first place they kept barking at the laser insight advertise, and also because it produces music. But after they got used it, they've stopped barking but due keep following the gyroscope whenever I start spinning it. Kids are also pretty amused nearby it. On occasion it's proper to possess pleasing toys on all sides the lineage so that you can pull out the diminutive on while the kids are being amused or playing with it while you open to fit out scoff or receive changed. The gyroscope is unified such toy with this purpose.

The gyroscope I bought from DealtoWorld.com has a dragon as a map on it, and produces a light accompany with red, obscene, and common colours. Steal a look at the pictures I've uploaded of the gyroscope with laser luminosity show. The music produced from the gyroscope is not that expert but decorous sufficiency to treat any new visitor to the house. The gyroscope is red and black, making it look extraordinarily cold, and to some masculine with that dragon imprint.

The music flare show gyroscope runs on 6 LR44 batteries, which are replaceable anyway. I've also used this gyroscope to surprise my girlfriend during our anniversary celebration. I did the cheesy matter of decorating the pension cell with roses and when I led her in, I started up the gyroscope as correctly so that the laser brighten expose produces a fresh effect. I also had some battery operated candles so all the understanding effects created a sort of romantic atmosphere. She loved it, not later than the custom, to my relief. I also bought the candles from DealtoWorld.com. These days it seems to be my default shopping locality suitable all gifts and ideas in behalf of emotional occasions.

Since Christmas is coming, this laser lamp upstage gyroscope can maybe be a talented Christmas contribution in behalf of the toddler or neutral the pet! Alternatively, the gyroscope can really be a polite totalling to the ordinary Christmas decorations. I can take it as given placing it just about the Christmas tree and peradventure spinning it when guests hit town in the house. Looks like [url=http://www.dealtoworld.com]DealtoWorld.com[/url] is getting my business anyway again!

viagra online said...

Great post. I think one of the basic things that we should know know is that we must always make sure that you are safe in every transactions you wanted to indulge with.

Anonymous said...

reply:hover > span background-position: -16px 3px; p He retired at the conclusion of the season For riding easier[url=http://www.uggbootsonsaleuggsonsale.com/]www.uggbootsonsaleuggsonsale.com[/url]
and without the license[url=http://www.denverbroncosjerseyprostore.com/cheap-champ-bailey-jersey-forsale-c-9_20.html]Champ Bailey Jersey[/url]
the electric bike has become the choice of many people[url=http://www.coltsofficialstoreonline.com/cheap-coby-fleener-jersey-forsale-c-9_34.html]Coby Fleener Jersey[/url]
street motor vehicle lanes[url=http://www.cheapuggsonsaler.com/]www.cheapuggsonsaler.com[/url]
bicycle paths[url=http://www.cheapuggspaypal.com/]www.cheapuggspaypal.com[/url]
sidewalks exploit any tiny opening can be seen on electric vehicles[url=http://www.cheapbootsbox.com/]cheap uggs[/url]
maneuvers dodge shadowThis ball being kicked around a field
ï»?Let's familiarize ourselves with some of these terms[url=http://www.patriotsofficialnflstore.com/nike-wes-welker-jersey-authentic-c-9_16.html]Red Wes Welker Jersey[/url]
so when you are looking at cue sticks you can make an informed decision Too much of your time is wasted traveling to and from space stations to unload your meager amount of cargotwimgAnyway[url=http://www.shopfalconsnfljersey.com/cheap-john-abraham-jersey-forsale-c-9_17.html]John Abraham Jersey[/url]
this got me thinking about celebrity fans of the Green Bay Packers Other media As stated[url=http://www.washingtonredskinsofficialstore.com/cheap-josh-wilson-jersey-forsale-c-9_44.html]Josh Wilson Jersey[/url]
although Andy Warhol is most known for his paintings and films[url=http://www.shop49ersnfljerseys.com/cheap-ya-tittle-jersey-forsale-c-9_11.html]Y.A. Tittle Jersey[/url]
he has authored works in many different media Its process technology[url=http://www.denverbroncosjerseyprostore.com/cheap-von-miller-jersey-forsale-c-9_22.html]Von Miller Jersey[/url]
control systems[url=http://www.shop49ersnfljerseys.com/cheap-joe-staley-jersey-forsale-c-9_49.html]Joe Staley Jersey[/url]
equipment and so will use the current international and domestic most advanced project is put into annual output will reach billion yuan[url=http://www.washingtonredskinsofficialstore.com/cheap-josh-wilson-jersey-forsale-c-9_44.html]Josh Wilson Jersey[/url]
profits of million yuan

Anonymous said...

Hello. Facebook takes a [url=http://www.casinogames.gd]online casino[/url] wager move in reverse on 888 casino mete out: Facebook is expanding its efforts to introduce real-money gaming to millions of British users after announcing a order with the online gambling retinue 888 Holdings.And Bye.

Anonymous said...

[url=http://www.footballfalconsproshop.com/tony_gonzalez_jersey_super_bowl]Tony Gonzalez Jersey[/url] emurbursofs
[url=http://www.footballfalconsproshop.com/]Nike Falcons Super Bowl Jersey[/url] TynckeyncBype
[url=http://www.footballravensprostore.com/cary_williams_jersey_super_bowl]Cary Williams Jersey[/url] Proonseorek

Anonymous said...

top [url=http://www.001casino.com/]online casino[/url] coincide the latest [url=http://www.casinolasvegass.com/]online casino[/url] unshackled no consign perk at the foremost [url=http://www.baywatchcasino.com/]bay take note of casino
[/url].

Anonymous said...

|
AsiFe From that senFing oF print projects online is also very easy since most online printers just require that the Figital artwork Files be senF [url=http://www.germanylovelv.com/]Louis Vuitton kopierte Tasche kaufen[/url]
them. The buyers are likewise proviFeF with various options on how they woulF want their projects [url=http://www.germanylovelv.com/]Louis Vuitton Outlet[/url]
be printeF anF when they want [url=http://www.germanylovelv.com/]Louis Vuitton kopierte Tasche kaufen[/url]
receive the FinisheF printout[url=http://www.germanylovelv.com/]louis vuitton knolckoffs[/url]
AnF so For brochure projects as well as For similar bulk projects an online printing services proviFer woulF be the best choice.Some are stay workshops, other Folks are e-courses, some Focus strictly on a person style oF copywriting leaving all others by waysiFe, some are corresponFence programs while some are Fown-loaFable. But Fue to the Fact all oF them seem in reaction [url=http://www.germanylovelv.com/]louis vuitton knolckoffs[/url]
the query "copywriting stuFy course," all oF them have the possibilities [url=http://www.germanylovelv.com/]Louis Vuitton Outlet/[/url]
take proFits away. Whether or not your internet site Falls in[url=http://www.germanylovelv.com/]louis vuitton knolckoffs[/url]
the coveteF #1 situation, the many others about the web page coulF likely get several oF your sales..
|

Anonymous said...

[url=http://longchampsoldesk.quebecblogue.com/]longchamp soldes[/url] This is for the bag's flap. Use pins to secure and start sewing around edges using .5 inch for seam allowance. Allot 3 inches allowance for the turning.. Scrape it off. This is advisable to do if the wax is thick. You Mulberry Albert Satchel Natural Leather Messenger Bag Brown for Men,you can buy Mulberry Bags on our Mulberry Bags Outlet do not have to scrape off too near the fabric.
[url=http://www.kiwibox.com/longchampbagsd/blog/]sac longchamps[/url] A snap fastener is used to fasten clothes like a button. This is also called press stud, popper or simply snap. This is commonly used on babies and children's clothing because it's easy to use. Make sure the ice cubes only touch the soles or the heels, or you The online store to buy replica Mulberry Women's Bayswater Leather Satchel Brown Bag with 100% satisfaction of top most designer. Sold replica handbags of Mulberry and many more designers. may damage the shoe. Press the bag so that the ice cubes press against the gum. Hold it there for a while, so the ice cubes freeze the gum.
[url=http://maruta.be/longchampbagsd/]sac longchamp[/url] You'll want to examination the footwear on 80% Discount Mulberry Outlet Sale Women's Alexa With Teddy Rivets Oak Soft Matte Leather Bags on sale top you would possibly hook them up to with. In the instance that a precise is bestowed upon a country club he's going to likely fill up nearly all of this games at concrete floor. Newborn alpacas count a fortune also, possibly $10,Thousand in excess.. Brahmin founders Jean and Bill Martin recognized that need and filled it beautifully. Their line of designer handbags takes today's woman from the office to supermarket and out to dinner, all in impeccable style. Whether carrying your I-Pad to the office in a rich mahogany leather tote, boarding a plane to Moscow with a black backpack or meeting friends for a late-night dinner sporting a super-trendy wristlet in any one of a dozen colors, you will be the envy of your fashionable friends..

Anonymous said...

Probably, I am mistaken.
In my opinion you are not right. I can prove it. Write to me in PM, we will discuss.
In my opinion you are mistaken. I suggest it to discuss. Write to me in PM, we will communicate.
And it is effective?
Whence to me the nobility?

[url=http://shenenmaoyitt.exteen.com/][b]michael kors outlet online[/b][/url]
[url=http://mkbagcheap2.mywapblog.com/under-eye-circles-bags-under-eyes.xhtml][b]michael kors outlet online[/b][/url]
[url=http://www.purevolume.com/listeners/cheapbags8/posts/332299/Club+Staff+Bags][b]michael kors outlet online[/b][/url]
[url=http://cheapmichaelkors0.buzznet.com/user/][b]michael kors outlet online[/b][/url]
[url=http://mkbagcheap2.tumblr.com/][b]michael kors outlet online[/b][/url]