The Quality of TDD 46
Kieth Braithwaite has made an interesting observation here. The basic idea is that code that has been written with TDD has a lower Cyclomatic Complexity per function compared to code that has not been written with TDD. If this is true then it could imply lower defects because of this.
Kieth’s metric takes in the code for an entire project and boils it down to a single number. His hypothesis is that a system written with TDD will always measure above a certain threshold, indicating very low CC; whereas systems written without TDD may or may not measure above that threshold.
Kieth has built a tool that you can get here that will generate this metric for most java projects. He and others have used this tool to measure many different systems. So far the hypothesis seems to hold water.
The metric can’t tell you if TDD was used; but it might just be able to tell you that it wasn’t used.
Braithwaite is a genius. Im sure this will work perfectly.
Hi Bob, Actually, its not so simple as that TDD code has less complexity per method absolutely (if only), but rather that there is a preference for more simple methods in TDD code.
What fascinates me about Rich’s data is that the minimum probability of defects comes at what might be considered quite a high complexity.
By the way, I’m working on a new version of the tool with some visualization features that makes the differences in codebases a little easier to grasp. Should be available sometime in the next couple of weeks.
Keith
(PS, the rule is “i before e, except when it’s not” ;)
This is a great tool for measuring complexity in Java code: http://www.martyandrews.net/resources/complexian.html
Another tool that I think could be interesting is Crap4j: http://www.crap4j.org
I just wanted to follow up to the point about Rich’s data showing low probabilities for surprisingly high complexity values.
The Enerjy data is calculated entirely at the file level, so you can’t compare the Enerjy numbers with the traditional 7-10 range that applies at method level. This comes back to one of the fundamental problems with CC these days – most metrics are measured at a file level but CC only makes sense at the method level. Averaging the CC over the file makes no sense as the whole point of it is to highlight methods with unusual values. For Enerjy we decided to just sum the CC of all methods in the file to get a file-level metric.
Another useful approach would be to create a static analysis rule that fires whenever a method has complexity over a certain threshold and then use the number of firings as a predictor. We had a hard time coming up with a threshold that worked well for real-world code, though. Values below around 20 seemed to fire very often and on code that, to our mind, didn’t need refactoring. Values above 20 just seemed pointless :-)
Mark
Well, just to be nasty, let me point out that in all 45,000 lines of FitNesse there is only one function with a CC > 20. It happens to be a big switch statement that translates http error codes into strings. e.g. 404->”Not Found”.
If Rich’s data is on a per file basis, it’s not CC (and shouldn’t be named CC). Rather it comes close to another metric called WMC or “Weighted Methods per Class”, which sums up CC values of a class. For a file based CC metric, it might have been better to take the maximum, but that way, the data presented is not that useful.
@Keith: Now, where does the magic minimum at 11 come from? Let me guess: in a typical code base we have a relevant amount of trivial, bean-like classes, usually without bugs. If we were looking at the distribution of the number of properties of these bean classes, we might find a maximum at around 5 or 6. Now each property has a getter and a setter with CC of 1, which results in a higher number of bean classes whose CC values sum up to something around 11. I’m pretty sure the function would be monotone increasing if these classes would have been excluded.
@Bob: I just analyzed fitnesse with STAN. You are right, the project has low CC values. However, to be nasty too, there are around 10 classes in the fitnesse tree with WMC > 38. According to Rich, these classes have > 50% probability of being fault-prone.
@Bob: Why not replace the switch statement with a Map?
Could do. But why? In this case the switch statement is simple, expressive, and terse.
@Mark: is there any chance of the enrjy results being written up in a more transparent style? I had actually missed the point that Christoph points out, that what that chart measures isn’t quite Cyclomatic Complexity. I actually didn’t find it easy to tell from the blog posting (and even more so the paper) exactly what it is that was being measured.
@bob: high CC methods doing problem-free, easy to understand, easy to test dispatching or marshaling tasks occur in more than one of the codebases I’ve looked at—they are a nice example of how any metric can be misleading if not interpreted properly.
By the way, Bob’s link has rotted and a new version of the tool is available form http://www.keithbraithwaite.demon.co.uk/professional/software/#measure
so i am coming
Hey dear your blog is very much rocking and stunning. This blog has main attraction and high quality features. Due to the latest posts, this blog is relatively famous among the readers of allover the world. You have provided enough information on many different topics. well done.
system written with TDD will always measure above a certain threshold, indi
Thanks for ur nice sharing!!It help me a lot with those information!!!
You would want this clarity of detail if you ventured out on a lake every day to fish for dinner.
They are different. When you want to know. When I come to here, I think I am in the right place. the web gives me a lot of infomation, it is very informative. I think lots of people can learn much here. I will come to here again. Thanks.
but it might just be able to tell you that it wasn’t used.
Had a good response nearly accomplished, ended up being evidence studying this & obtained wiped out through an ad pertaining to Shipwreck drops. Been age ranges since i have examined throughout here & remaining because the large internet site alterations lsat summer produced contributing by way of dial-up Distressing. I observe situations are quite similar. Sleepless & sprang over from the Etsy community forums which usually didn’t seize me tonight… Spend some time stalking on the forums & checking out goods available for sale & lately distributed. There had been about 197,500 diamond jewelry listings while i opened our shop (NGHDesigns) in late July. There are over Three hundred,500 today. I’ve had a few achievement & get pleasure from contributing generally there, yet feel glad that’s not the way you maintain a new roof over our mind. Some dealers prosper generally there, others never offer one thing. Even probably the most amazing goods are generally buried inside heap in mere min’s
Looking for the latest white iphone 4 Conversion Kit? I am just looking for a web to satisfy all my need. Come and take it home!
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.
So far the hypothesis seems to hold water.
Another useful approach would be to create a static analysis rule that fires whenever a method has complexity over a certain threshold and then use the number of firings as a predictor.
Now each property has a getter and a setter with CC of 1, which results in a higher number of bean classes whose CC values sum up to something around 11. I’m pretty sure the function would be monotone increasing if these classes would have been excluded.
We are the professional t-shirts manufacturer. t-shirts supplier. t-shirts factory, custom t-shirts.
Buy $10 Replica Designer Sunglasses with 3-day FREE SHIPPING At fashion-world4u you find Imitation
Finally, got what I was looking for!! Thanks.
I love this one. A very good post. Thank you. roofing venice
i like it..
internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.
Your blog is awesome! :-)
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.
Online UK costume and fashion jewellery shop with,
very nice article ! quite helpful for a newbie like me !
hmm ,i’m not sure if this is what i’m looking for but anyway this is interresting and could be useful some day,thanks for taking time to write such cool stuff
i think this can be bookmarked for future referenses , i think i could make use of this ,many thanks for the time you spend writing this , best regards for Canada
hmm ,i’m not sure if this is what i’m looking for but anyway this is interresting and could be useful some day,thanks for taking time to write such cool stuff
Wonderful technology is visible in this blog that Director of Operations Job Description to using the nice services in this blog Accounting Job Description This is really superb info is visible in this blog that to using the great technology in this blog and wonderful technology is visible in this blog Graphic Designer Job Description I had really satisfied by Legal Assistant Job Description the nice technology in this blog
The actual course is called fishery studies, and you study general aquatics and fishery management. Tom Felton
I love this one. A very good post. Thank you. Brisbane Limo Hire
I love this one. A very good post. Thank you. Brisbane Limo Hire
It is true that if we want to make a great improve in programing. we need do understant the exactly mean of each conception. And we need do practice. so, why not think about doing it now.
The Quality of TDD 41 hoo,good article!!I like the post!64
The Quality of TDD 42 good post113
The quality of free hacks is best. Download them easy as a rocket! :D
Gone are the days when designing and selling baby clothes used to be for those people who had lots of money?
With more than 20 years of experience, Intertech provides an extensive integrated operational ability from design to production of molds 100% made in Taiwan. Additional to our own mold making factory, we also cooperate with our team vendors to form a very strong working force in Taiwan.
For the overseas market, we work very closely with local representatives in order to take care of the technical communication and after-sales service to our customers. We also participate in the EUROMOLD & FAKUMA exhibitions and meet our customers every year in Europe. By concentrating on mold “niche markets”, we play a very useful mold maker role from the Far East whenever customers want to develop their new projects. We provide services from A to Z to our customers on a very economic cost and effect basis.