As the tests get more specific, the code gets more generic. 100
I tweeted this not too long ago. The basic idea is that as you add tests, the tests get more and more specific. This makes sense since tests are, after all, specifications. The more specifications you have, the more specific the whole body of specifications becomes.
As a general rule, good design dictates that the more specific your requirements become, the more general your code needs to be. This is saying roughly the same thing as Greenspun’s Tenth Rule of Programming: “Any sufficiently complicated [...] program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp.” Or rather, as more and more constraints pile upon a program, the designers look for ways to push those constraints out of the program itself and into the data.
In return for my tweet people asked for examples.
One of the better examples (though perhaps a bit trivial) is the Prime Factors Kata. This lovely little experiment grows and grows as you add test cases, and then suddenly collapses into an elegant three line algorithm.
The tests continue to become ever more specific. The production code starts out just as specific as the tests. But with the second or third test the programmer must make a decision. He can write the production code to mirror the tests (i.e. writing it as an if/else statement that detects which test is running and supplying the expected answer) or he can come up with some kind of more general algorithm that satisfies the tests without looking anything like them.
The algorithm grows and warps and twists; and then, just when it looks like it’s destined to become a wretched mess; it simply evaporates into a lovely little three line nested loop.
We see the principle at work in other ways as well. Often the programmers have a whole list of tests that they know must pass. As they write them one by one, they write the production code that satisfies them. Then, as in the Bowling Game Kata the tests start to pass unexpectedly. You were done with the code, and you weren’t aware of it. You continue writing tests, expecting one to fail, but they all pass. The test code grows, but the production code remains the same.
Sometimes this happens in a less surprising way. Sometimes you know that you have implemented an algorithm that will pass all remaining tests, but you write those tests anyway because they are part of the specification
The point is that test code and production code do not grow at the same rate. Indeed, as the application increases in complexity, the test code grows at a rate that is faster than the production code. Sometimes the production code actually shrinks as the test code grows because the programmers moved a load of functionality out of the code and into the data.
Consider FitNesse. A year ago there were 45,000 lines of code, of which 15,000 were tests, so 33% of the total were tests.
Now Fitnesse is 58,000 lines of code of which 26,000 are tests. We added 13,000 lines of code overall, but 8,000 (61%), are tests! The tests have grown to over 44% of the total.
I like to see something about the maintainability of your tests suite. When doing functional changes to the code what is a good way to change the tests? I thought of two approaches (also blogged about it here: http://blog.fohjin.com/blog/2009/5/14/How_to_Re_factor_or_Change_Behavior_using_TDD).
First approach would be to make the changes to the code and adjust the tests afterward, but then you are not doing TDD anymore. This might be ok for small functional changes but for larger ones I would like to follow the second approach
Create new tests to cover your changed functionality/behavior doing TDD and keep going until you feel that you have implemented it correctly with the correct tests. While doing this ignore any broken tests and if a test doesn’t compile then commented the body of it out and add assert.fail(). Then when you are done you should have x number of failing tests which after proper investigation you could delete.
Now second thing is how you group your tests together, the clasic (as I understand it) way in TDD is that you group them by class that they test, and while this is fine for smaller systems I feel you run into test maintains issues rather quickly. After Jeremy Miller did a presentation at NDC we talked about this and he groups the tests by functionality/behavior (more like BDD) and in this I could see great benefit. Doing this will I believe help making functional changes to your code and tests. What is your opinion on this?
Btw I have your book (clean code) in front of me to start reading it, so if the answer is in there that would suffice as an reply as well :)
When changing the behaviour in a big way, I would write completely new classes and then when they are complete enough to replace the old classes, I would change the system to begin using the new classes. This is what Kent Beck calls Parallel Strategy in http://www.infoq.com/presentations/responsive-design starting around 37min (great presentation, btw).
After doing the change, I would delete all the old code and tests that were replaced. When TDD’ing the new code, I would probably have a look at the old tests, to make sure that I cover all the wanted behaviour and corner cases.
The way that I like to group and organize tests is closer to BDD. I would not write tests like Uncle Bob in his Bowling Game Kata – that style might be called “tests as examples”. Instead I would write “tests as specification”.
In case of the bowling game, the test names would be such that you could print them in a book under the title “rules of scoring in bowling”. Similar to page 2 (“Scoring Bowling”) of Uncle Bob’s Bowling Game Kata presentation. I haven’t yet tried writing a Bowling Game Kata with my style (maybe I should try it), but you can see my style in the case of a Tetris game here: http://github.com/orfjackal/tdd-tetris-tutorial/tree/master/src/test/java/tetris
The reason why I use this style, is that when the requirements have changed and some tests fail, then I can read the name of the test and know that why that test was written – what is the behaviour specified by that test. Then it’s easy to evaluate whether that test is still needed and its code just has to fixed, or whether the test is outdated and should be removed. It also helps when writing new code, that have all corner cases and combinations been covered by the tests.
Hi Esko,
Thanks for your feedback and link.
what an interesting truth, right?
I agree when you are done you should have x number of failing tests which after proper investigation you could delete.
Clean code is most important these days
Make sure the room is big enough to employ all votes, lol.. Different individual will respond differently. You have no way but to anticipate that.
that real significant changes are often the ones that go unnoticed, because they Make Things Work As They Are Supposed To.
OK, I got it. Thanks for your sharing. That is very interesting Smile I love reading and I am always searching for informative information like this.
Good luck then. It will be thrilling if this is the first project for them. But let them learn their ways. Steam showers
This is usually achieved by combining static code analysis (Coverity, Klockwork or their free analogs) with dynamic analysis by running a tests against instrumented application (profiler + memory checker). Unfortunately, this is hard to automate test algorythms, most tools are kind of “recorders” able to record traffic/keys/signals – depending on domain and replay them (with minimal changes/substitutions like session ID/user/etc)
This is usually achieved by combining static code analysis (Coverity, Klockwork or their free analogs) with dynamic analysis by running a tests against instrumented application (profiler + memory checker). Unfortunately, this is hard to automate test algorythms, most tools are kind of “recorders” able to record traffic/keys/signals – depending on domain and replay them (with minimal changes/substitutions like session ID/user/etc)
Great article with lots of information, thanks!
Wide range of web hosting services are accessible, such as cheap vps , email hosting, Unix hosting, forex vps , Windows hosting, Linux web hosting windows vps etc. We hope you will find a cheap hosting company.
Ok, so I’m getting good feedback on the first picture. Now for a series of pictures.
Hi there, everyone! The March On Washington DC is one of America’s most trusted news sources. The site publishes Upcoming News, allows Submission of a News Story and gives users or members a chance to create Groups that allow users to share articles with other members with whom they have a common topic of interest. We concentrate on all these fields: News, Politics, Finance, Health, Technology, Science, Entertainment, World, Living, and Travel. Feel free to visit our site anytime :) Good day!
We are professional Led Tube Light, Led Panel Light, T8 Led Tube, Led Flood Light, Led Grow Light.Good quality and competitive price is your best choice.If you want,please contact us right now! We specialized in researching and developing, producing and marketing Car AC Parts, Car AC Hose, AC Parts. Good quality and competitive price is your best choice.If you want,please contact us right now! LV??, Gucci??, Bally??
We are professional Led Tube Light, Led Panel Light, T8 Led Tube , Led Flood Light, Led Grow Light.Good quality and competitive price is your best choice.If you want,please contact us right now! We specialized in researching and developing, producing and marketing Car AC Parts, Car AC Hose, AC Parts. Good quality and competitive price is your best choice.If you want,please contact us right now! LV??, Gucci??, Bally??
It’s nice!!
You are great!
It’s sorry to hear that Some white iPhone 4 buyers have reported signal reduction when the phone is held in certain ways, especially in the left hand, as the antenna problem is in the bottom left corner of the phone’s side casing. Is that mean i have to wait longer to get the white iphone 4?
thanks for Moncler Jackets || Christian louboutin UK || Moncler coats || Christian louboutin shoes || Christian louboutin pumps your post!
Outsource Mastery is your perfect business partner in helping you live to your company’s full potential This may mean a lot of changes, a big change for or even little changes that matter so much for your organization and business in the long run.
graphic design website design offers online web solution web design offers Market web design
We are engaged in gearbox,radial piston motor,axial piston motor,piston motor,slewing transmission,danfoss motor,hydraulic orbital motor,hydraulic steering,hydraulic steering unit,hydraulic winch. All products are strictly tested before delivery by testing bench and comprehensive testing facilities to ensure the quality.
I really like this essay. Thank you for writing it so seriously. I want to recommend it for my friends strongly. iPad PDF Transfer for Mac can help you transfer ebooks in PDF format from ipad to mac/iTunes.
This lovely little experiment grows and grows as you add test cases, and then suddenly collapses into an elegant three line algorithm.
Sometimes you know that you have implemented an algorithm that will pass all remaining tests, but you write those tests anyway because they are part of the specification
Hi Everyone,
We carry a wide range of parts in-stock including replacement LCD
panels for current models of laptops, replacement screens for GPS
navigators, camera displays, lenses and more! In most cases we can
have your laptop up and running again in under one business day. At
Ficks repair we are so confident of being the cheapest independent
electronics wokshop in Australia that if you can provide a quote for cheaper we will beat it by 15 percent! We are a small BRISBANE based electronics repair boutique that
specializes in phisycal damage..
Thanks, come and visit our site for full details
Your site is amazing.I am very impressed to see this,i want to come back for visiting your site.Keep doing Good as well as you can.
Clean code is most important these days
Doing this will I believe help making functional changes to your code and tests. What is your opinion on this?
Ct Credit Bureau offers full tenant screening services to property managers, landlords, and others in the real estate and rental industry.
The site publishes Upcoming News, allows Submission of a News Story and gives users or members a chance to create Groups that allow users to share articles with other members with whom they have a common topic of interest.
The trigger notices when you try to create a column without a generic type and can lead to wrong behaviors in some cases.Thanks for shaing the informative post. Regards. david77 – Cat Tree
This triggers notices when you try to create a column without a generic type and can lead to wrong behaviors in some cases.Thanks for sharing the informative post. Regards. david77
The basic idea is that as you add tests, the tests get more and more specific. This makes sense since tests are, after all, specifications.Thanks for sharing the informative post. Regards. david77
The rtc test driver simulates specific interrupts by echoing to the sys interface. Those were the update, alarm and periodic interrupts. Thanks for sharing the informative post. Regards. david77
The training to object oriented developers looking to accelerate development with methodologies such as XP and advanced software design.Thanks for sharing the informative post. Regards. david77
Buy sunglass
I really like this taxonomy of change. It goes a long way towards regularizing code changes in the same way that refactoring regularized design changes. I’m looking forward to trying it self-consciously and seeing what happens to my experience of coding.
The grill is a generic build system designed to have the build recipes decoupled from the implementation of the build system. Thanks for sharing the informative post. Regards. david77
Thanks for this article.I like its.As to me it’s good job.I wait ur next articles and I will read ur new articles.
Interesting observation about the code there, clean code is so important these days.
The arabian Sea and Gulf of Aden on the south and the Red Sea on the west it borders only two other countrie. Thanks for sharing the informative post. Regards. david77 – <a rel=”new tab” href=”http://www.myonlinepractice.com/ ”>medical practice management software
Thanks for your sharing. That is very interesting Smile I love reading and I am always searching for informative information like this.
Sometimes you know that you have implemented an algorithm that will pass all remaining tests, but you write those tests anyway because they are part of the specification
The translations set has one source and any number translations in one of all the translations are kept up to date or out based of whether the source message has been changed significantly. Thanks for sharing the informative post. Regards. david77 – new top level domains
A bad beginning makes a bad ending. A bird in the hand is worth than two in the bush. A year’s plan starts with
spring. Bad news has wings. Better to ask the way than go astray. By reading we enrich the mind, by conversation we
polish it. Custom makes all things easy. He is not fit to command others that cannot command himself. He laughs best
who laughs last. tiffany and co outlet
This is great stuff. I have to say i am impressed by your ideas. roofing
I wouldn’t say they are duplicating each other. More like they complement each other. You’re defining each method from both the inside and the outside. To paraphrase Uncle Bob, it’s like double entry accounting for your code
Thanks for sharing.
internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.
Make sure the room is big enough to employ all votes, I love it.
Farkl? ki?ilerle online okey oyunu oynayabilece?iniz bu heyecan verici oyunu hemen bilgisayarlar?n?za indirin. Okey oyunu indir, bilgisayar?na kur ve oyanamaya hemen ba?la. www.okeyoyunuindir.com Thank you…
The Agile and Object Oriented Design training mentoring coaching and development. Extreme Programming XP object oriented consulting training courses.Thanks for sharing the informative post. Regards. david77
Hey great article Hope to see more in the future.
How can it be that you receive a lot super idea as this topic? Entirely the good research paper writing services get know the way to compose such great custom thesis and custom dissertation.
This is a kind of sites which gives more benifits … It is great… Thanks for it.. I hope it will helps to more people.
I like the precious information you be offering to your articles. I will be able to bookmark your blog and feature my kids check up right here generally. I am quite positive they are going to be told a lot of new stuff right here than any one else!
I like this very much, I added you to my bookmarks. hope you can visit my web too. I would say this is a very nice and great article, I love this very much and will visit your site frequently for other nice articles. Please visit mine too. .
Have the christian louboutin patent leather pumps is a happy thing. Here have the most complete kinds of christian louboutin leather platform pumps.
I found that his foot odors never bring us to death.I never regret buying these beats by dr dre studio for him. These beats by dr dre solo are just the same as selling in the franchise store.Or even better.
Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!.
This looks absolutely perfect. All these tinny details are made with lot of background knowledge. I like it a lot. This was a useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful. .
Blog posts about wedding and bridal are always rare to find , at least with great quality,you qualify for a great blog post writer title,kep the great job happening
???????
bridal are
Great article on software testing. The testing of sftware application not only tests whether the critical functionality works or not but also can help imporve the performance of the application. Various kinds of testing such as white-box, black-box, automated and manual all ensure that application meets business requirements and helps the service provider get more out of their product.
A great idea, indeed… Cheers, Urlaubskredit
Thanks for your sharing. That is very interesting Smile I love reading and I am always searching for informative information like this.
How can it be that you receive a lot super idea as this topic? Entirely the good research paper writing services get know the way to compose such great custom thesis and custom dissertation.
How can it be that you receive a lot super idea as this topic? Entirely the good research paper writing services get know the way to compose such great custom thesis and custom dissertation.
I like the precious information you be offering to your articles. I will be able to bookmark your blog and feature my kids check up right here generally. I am quite positive they are going to be told a lot of new stuff right here than any one else!
Thanks for this article.I like its.As to me it’s good job.I wait ur next articles and I will read ur new articles.
Hey.. its really a great news.
Regards iPhone Reapir
The Daily Reviewer selects only the world’s top blogs We sift through thousands of blogs daily to present you the world’s best writers. The blogs that we include are authoritative on their respective niche topics and are widely read. Thanks for sharing the informative post.
The blogs that we include are authoritative on their respective niche topics and are widely read. Thanks for sharing the informative post.high quality headphones new design headphones
This is my first opportunity to visit this website. I found some interesting things and I will apply to the development of my blog. Thanks for sharing useful information.
Your algorithm is very smart. It is very interesting to conduct tests like these over a longer period of time. Thanks for sharing this.
In the era of leather and sheepskin is so common, can not meet all the needs of womenGucci Wallets Gucci Hobo Bags Gucci Accessories Gucci Accessories Gucci Top Handles Gucci Shoulder Bags Gucci Clutches
Moncler Jackets Mensis
your best alternative,Welcome to our store to Moncler Down Coats
I saw this one and fell in love! I must admit i was dubious about ordering a dress from a overseas company, but i can’t praise Lightinthebox enough for there professionalism, quality, communications, and swift delivery. I ordered a custom size and the dress was delivered in just over 2 weeks to the UK. One word sums up the quality of this dress… Wow!!! The material is really good quality and the craftsmanship is second to none
Hello there , I do imagine that is a superb web site. I stumbled on it on Yahoo , i’ll arrive back again when once more. Income and flexibility may be the greatest method to adjust, could you be abundant and support others.
A: 18 B: Yes, the dam is stopping water these days. And the water is rising 2 meters every day until it is 135 meters high. A: Oh, no wonder it’s said the beautiful scenery (??) of Kuimen will be under water. What a pity! B: 19 It has been copied in another place with some other places of interest. A: Great?I want to go to the Three Gorges this summer. Would you like to go there with me again? B: I’d love to! 20 women’s dresses G.We’ll see a new Three Gorges then. women’s dresses on sale F.It’s reported that it has changed a lot.
women’s dresses for sale E.Where have you been?
buy women’s dresses D.Is it hard to build the dam?
sell women’s dresses cheap women’s dresses A.Is the dam beginning to work? B.But I haven’t been there yet. C.Don’t worry.
trong>wholesale women’s dresses fashion dresses brand dresses for womendiscount women’s dresses
evening dress B: Right. As you know, we’ve built a great dam (?) across the Changjiang River.
girl’s dresses
sell Gucci Dresses A: Hi, Zhou Qiang. Haven’t seen you for too long! 16
buy Gucci Dresses B: I’ve just been to the Three Gorges (??). A: Really? 17 (B) ????????
such a grt site i found some of article very valuable for me
You had 42 blacks that ran on the Republican ticket this Cycle, 14 made of them made it to the general election and two of us made it to the House of Representatives. So I think that there is a new movement that needs to have a voice in the Congressional Black Caucus.
Slewing bearing called slewing ring bearings, is a comprehensive load to bear a large bearing, can bear large axial, radial load and overturning moment. http://www.1stbearing.com
www.hkf.so GANGHUI Lighting Technology (Fujian) Co., Ltd. orientates energy-saving and environment protection as core enterprise when we established. We concentrate on veloping the new industry and provide high-quality energy-saving products and good service for mankind sustainable development.led lamp led ceiling light led spotlight
The professional design make you foot more comfortable. Even more tantalizing,this pattern make your legs look as long as you can,it will make you looked more attractive.Moveover,it has reasonable price.If you are a popular woman,do not miss it.
Technical details of Christian Louboutin Velours Scrunch Suede Boots Coffee:
Fashion, delicate, luxurious Christian louboutins shoes on sale, one of its series is Christian Louboutin Tall Boots, is urbanism collocation. This Christian louboutins shoes design makes people new and refreshing. Red soles shoes is personality, your charm will be wonderful performance.
Very nice article. Somewhat related to [url=”http://seosuisse.ch”]Seo[/url] . Thanks for sharing
Very nice information. This is somewhat related on learning SEO ... Thanks for sharing. very intelligent writer.
How many people understand this? it is a good choice to make a copy of it and save it on computer. We can retrieve them when necessary.
Every women always has Christian Louboutins Wedding Shoes turn of fame but it also has its own goodbyes.
Gucci Sac a main, Sac Prada?Sac a main Prada?Sac Prada Prix?Sac Gucci, Gucci, Sacs a dos Gucci, Sacs à main Gucci, Polo Sac Gucci, Doudoune Moncler, Moncler Veste,
I like this very much, I added you to my bookmarks. hope you can visit my web too. I would say this is a very nice and great article, I love this very much and will visit your site frequently for other nice articles. Please visit mine too. .
How many people understand this? it is a good choice to make a copy of it and save it on computer. We can retrieve them when necessary.
Hello there , I do imagine that is a superb web site. I stumbled on it on Yahoo , i’ll arrive back again when once more. Income and flexibility may be the greatest method to adjust, could you be abundant and support others.
This is my first opportunity to visit this website. I found some interesting things and I will apply to the development of my blog. Thanks for sharing useful information.
This is a kind of sites which gives more benifits … It is great… Thanks for it.. I hope it will helps to more people.
As the tests get more specific, the code gets more generic. 96 good post70
As the tests get more specific, the code gets more generic. 97 hoo,good article!!I like the post!159
Designer bags are quite expensive, and not every woman actually has the money to be able to buy a lot of designer bags?
Extrêmement régulièrement je vais à ce site. Il est très beaucoup, c’est agréable pour moi. Merci de l’auteur!lunettes de soleil rayban