Living the Test Driven Dream

by Matt 6. August 2006 18:23

I find myself in an odd situation.

I'm doing maintenance programming.

And I'm enjoying it.

Maintenance programming sucks. It's the crazy art of taking someone else's code, guessing what it does, closing your eyes, gritting your teeth and changing something that inevitably breaks as soon as you get it live. It's a dangerous place, fraught with peril. It's depressing and demotivating and dull. Everyone has to do it at some point, and everyone hates it.

But I've made a discovery. Maintenance programming doesn't suck; it's not the work itself that's so bad, it's how you do it. Or rather, it's how it makes you feel.

Look at that description of maintenance programming again. OK, it's somewhat exaggerated and has a tongue planted firmly in it's cheek, but it still holds true. Developers do hate it, and get demotivated and depressed and demoralised. And here's the key - look at all that negative emotion! Things tend to go wrong when you do maintenance programming. And you're looking at other people's code and you don't like how it's structured, and you don't understand it, and it's all just so much stress and fear and general bad vibes.

This emotional impact shouldn't be under-estimated. This stress and fear is directly contributing to the depressed and demoralised feeling. And it's dull because you can't change the structure to something nicer because you're too frightened of breaking things! Who really wants to work in these conditions?

That's right. Maintenance programming is rubbish because of the emotional impact it has on you.

The good news is that this can all be fixed, and very easily. All it needs is some proper unit tests. And doing things test driven is even better.

I've had the luxury of spending the last couple of years working almost exclusively in .net, and there I've been really rather strict about unit testing, and test driven development (not an easy skill to learn, but once things have clicked, there's no going back). But that was all new code. Or so I thought at the time. Looking back it's fairly obvious that I was doing a lot of maintenance programming then, too. I haven't been writing brand spanking new code every single day for the past couple of years! I was changing things and tweaking things and fixing things, just like maintenance programming. But it didn't feel like it. There was no fear, no stress, no depression, no demotivation. And that's because I had a huge safety net of unit tests. Since the tests had been there before the code was even written, this was just taken for granted, and changes were cheap and safe.

But what if the tests aren't there already? This is where Michael Feathers becomes your new best friend. Go get his book Working Effectively with Legacy Code. It deals entirely with this situation, and has guidance and advice for what to do in this situation. It defines legacy code as code without tests. And the basic rule of the book is that you don't touch a single line of existing code until you've got it covered in tests. The hard part is inserting tests where they weren't designed to go, and that's where a large amount of the book comes in handy.

My current project came with some "prototype" code - a single 5000 line C file written by someone else. I had to get this production ready. Are you feeling the fear yet? Me too.

There was only one thing for it. Unit testing in C++. I'm now using Eclipse with a rather nice CxxTest plugin. I've got the full red-green-refactor cycle going, loads of unit tests, and it's all working really rather well.

And the most surprising thing was how it all made me feel.

I'm actually enjoying maintenance programming. I'm not worried about breaking something, because I've got confidence in my tests. I'm not worried about lack of knowledge, because I just write a test that demonstrates how it works. And, even more positively, it's incredibly satisfying to keep the red/green bar green, and to watch the number of unit tests increase, knowing that the quality and maintainability of the project is increasing with every new test. Instead of being limited by negativity, I've got all the fun of deciding how to best improve the structure of the code.

Who would have thought coding could be quite this emotional?

Tags:

Comments (23) -

suv review
suv review
7/20/2011 10:38:36 PM #

it ti permette di orientarti con semplicità nel pulviscolare niverso di Moncler.Troverai le indicazioni per lo spaccio o negozio Moncler più vicino a casa tua felpe moncler, pantaloni e abbigliamento sportivo.

Reply

ipad features
ipad features
7/24/2011 3:42:00 AM #

hi!,I like your writing so so much! proportion we communicate extra about your post on AOL? I require a specialist in this area to unravel my problem. May be that's you! Taking a look forward to see you.

Reply

Philix
Philix United States
11/20/2015 1:15:09 AM #

ace site

Reply

Hannah Barbarino
Hannah Barbarino United States
1/15/2016 5:45:56 AM #

Well good for you! I have a lot but one I just thought of was when you lick a crease of paper so that it'll rip in a straight line and it actually tears in a frayed straight line rather than rips awkwardly. I love that bleachy taste and that bleachy satisfaction.

Reply

Silvana Bellipanni
Silvana Bellipanni United States
1/15/2016 8:54:34 AM #

Thaaaat IS awesome! lol hehe

Reply

Ramon Larrier
Ramon Larrier United States
3/27/2017 3:27:30 AM #

This is a great website with some great info

Reply

專業團隊,為你提供私人貸款、業主貸款及物業按揭服務,及時雨撐你每一步。

Reply

肚紋
肚紋 United States
10/8/2018 8:07:22 PM #

倩碧眼部护理精华露(倩碧滚珠眼霜,走珠眼霜),利落的滚珠设计,清爽按摩间释放多重修护成分:迷迭香,木犀草精华,配合咖啡因,加速眼部微循环,通畅水分排出,轻松赶走浮肿,淡退下眼袋和黑眼圈,唤醒神采!

Reply

THE FACE SHOP 菲詩小舖 【唇部彩妝】DISNEY款光潤唇釉的商品介紹   THE FACE SHOP 菲詩小舖,唇部彩妝,DISNEY款光潤唇釉       

Reply

Alphonse Heebsh
Alphonse Heebsh United States
10/12/2018 4:00:35 AM #

Hello there! I know this is kinda off topic but I was wondering which blog platform are you using for this website? I'm getting sick and tired of Wordpress because I've had problems with hackers and I'm looking at options for another platform. I would be awesome if you could point me in the direction of a good platform.

Reply

CLEVIEL 高濃度透明質酸
CLEVIEL 高濃度透明質酸 United States
10/13/2018 3:22:47 PM #

除皺特點 純度高,效果好 見效迅速,無創無痛 安全精準,表情自然 唯一在臨床有20多年的注射材料,全球超過11000000人使用 適用範圍 魚尾紋、額頭紋、眉間紋、鼻紋和頸部皺紋都可以祛除; 最適合於早期的、不太明顯的皺紋 不須使用任何的鎮靜劑或局部麻醉劑,且Botox除皺治療後可立即繼續進行正常的活動。 Botox除皺可以利用午休時間約診即可,完全不影響工作的安排。BOTOX肉毒桿菌素是一種高度純化的蛋白質,經過注射之後,能夠使導致動態皺紋的肌肉得到放鬆,它能夠阻斷導致肌肉收縮的神經細胞,使面部線條變得平滑並防止新皺紋形成。全球銷量第一品牌 在中國唯一獲得SFDA、FDA批准用於醫療美容的肉毒桿菌素 唯一一個擁有40年安全記錄的肉毒桿菌素 在70個國家獲得批准使用 BOTOX肉毒杆菌素

Reply

Thora Naffziger
Thora Naffziger United States
10/13/2018 11:59:50 PM #

wonderful article, I enjoy it. I also buy ambien a lot. You ought to buy ambien as well. I will journey to the full USA and buy ambien there and in other areas to. i will be downtown, you know for what ? just to buy ambien. I will sleep a lot following buy ambien and that it constantly make me sense so good. I will be buy ambien in a pharmacy or one more spots, whatever the existence just take me .

Reply

Carmine Ottilige
Carmine Ottilige United States
10/15/2018 12:29:43 AM #

I have to express some thanks to you just for bailing me out of this setting. Just after browsing throughout the search engines and obtaining tricks which were not beneficial, I thought my entire life was gone. Existing without the presence of strategies to the difficulties you have solved by means of your main post is a serious case, and those which might have in a wrong way affected my entire career if I had not encountered your blog post. Your main mastery and kindness in taking care of every aspect was valuable. I don't know what I would've done if I had not come upon such a stuff like this. I can also now relish my future. Thanks for your time very much for your expert and result oriented help. I won't be reluctant to suggest the blog to any individual who would like care on this topic.

Reply

胜肽激活養髮療程
胜肽激活養髮療程 United States
10/16/2018 2:59:12 PM #

含藥化妝品配方能去角質、去除導致痘痘的多餘油脂。

Reply

醫學美容 水解 cosmetic.wiki
醫學美容 水解 cosmetic.wiki United States
10/17/2018 4:52:51 PM #

Shylina 萱琳娜 【臉部保養】玫瑰淨白卸妝露的商品介紹   Shylina 萱琳娜,臉部保養,玫瑰淨白卸妝露       

Reply

Dianne Brindisi
Dianne Brindisi United States
10/18/2018 3:29:58 AM #

I have been surfing online greater than 3 hours lately, yet I by no means found any interesting article like yours. It’s beautiful worth sufficient for me. In my opinion, if all web owners and bloggers made excellent content as you probably did, the net will likely be a lot more useful than ever before.

Reply

Jane Tighe
Jane Tighe United States
10/18/2018 10:48:41 PM #

I precisely had to thank you very much once more. I do not know the things I might have tried without the actual secrets discussed by you regarding my theme. This was a very difficult crisis for me, however , noticing your well-written form you processed it forced me to cry for fulfillment. I am grateful for your help and then hope you really know what a powerful job you are always accomplishing teaching many others through the use of your websites. More than likely you've never come across any of us.

Reply

Rana Ship
Rana Ship United States
10/19/2018 5:11:52 PM #

I simply needed to thank you so much yet again. I do not know the things I would've used without the actual ways shared by you relating to that question. It became a very hard condition in my position, nevertheless being able to view a skilled strategy you treated the issue forced me to weep for contentment. I will be happier for this advice as well as believe you realize what an amazing job you have been carrying out instructing people by way of your web blog. Most probably you have never got to know all of us.

Reply

Marita Guiberteau
Marita Guiberteau United States
10/20/2018 7:06:35 AM #

Thanks for the auspicious writeup. It in fact used to be a leisure account it. Glance complicated to far brought agreeable from you! However, how can we keep up a correspondence?

Reply

Susan Kreiman
Susan Kreiman United States
10/20/2018 11:16:09 PM #

I think this is one of the most vital information for me. And i am glad reading your article. But want to remark on few general things, The site style is ideal, the articles is really nice : D. Good job, cheers

Reply

醫學美容 吊線 cosmetic.wiki
醫學美容 吊線 cosmetic.wiki United States
10/20/2018 11:24:06 PM #

EVELINE 【臉部保養】高效嫩白潤膚霜的商品介紹   EVELINE,臉部保養,高效嫩白潤膚霜       

Reply

Derrick Lingbeck
Derrick Lingbeck United States
10/24/2018 1:25:25 AM #

Of course, what a splendid site and illuminating posts, I will bookmark your website.All the Best!

Reply

Football Solutions Scott Wright
Football Solutions Scott Wright United States
11/4/2018 4:39:01 PM #

Everton manager Roberto Martinez has said the club would accept an entry into next season's Europa League through their fairplay record. Roberto Martinez admits Everton would 'embrace' fairplay entry into Europa League

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading

Rel=Me

Month List

RecentComments

Comment RSS