Clean Code and Battle Scarred Architecture 94

Posted by Uncle Bob Wed, 20 May 2009 22:35:00 GMT

If you go here you’ll see that I struggle to keep the CRAP out of FitNesse. Despite the whimsical name of this metric (which I take a perverse delight in), I find it to be remarkably useful.

CRAP is a metric that is applied to each function in the system. The formula for CRAP is: CRAP = comp(f)2. X (1 – cov(f)/100)3. + comp(f)

Where comp(f) = the cyclomatic complexity of the function f. and cov(f) = the unit test coverage of function f.

So a function’s CRAP will be small iff the cyclomatic complexity is low and the test coverage is high. CRAP will be huge if cyclomatic complexity is high, and there is no coverage.

What does this have to do with architecture? Read on…

I work very hard to keep the ratio of crappy methods near .1%. Of the 5643 methods in FitNesse, only 6 are crappy, and five of those I have no control over.

If you study the graph you can see how quickly I react to even the slightest uptick in crap. I don’t tolerate it because it means that either I’ve got a horrifically complex method that needs to be refactored, or (and this is far more likely) I’ve got a method that isn’t sufficiently tested.

Why am I so fastidious about this? Why am I so concerned about keeping the crap out of FitNesse? The reason is pretty simple. It’s the least I can do.

If you look inside of FitNesse, you’ll find that there are lots of structures and decisions that don’t seem to make a lot of sense at first reading. There are complexities and abstractions that will leave you shaking your head.

For example. We generate all our HTML in code. Yes, you read that correctly. We write Java code that constructs HTML. And yes, that means we are slinging angle brackets around.

To be fair, we’ve managed to move most of the angle bracket slingers into a single module that hides the HTML construction behind an abstraction barrier. This helps a lot, but cripe who would sling angle brackets when template system are so prevalent? I hope nobody. But FitNesse was not conceived at a time when template systems made sense (at least to us).

Fear not, I am working through the Fitnesse code replacing the HTML generation with Velocity templates. It’ll take some time, but I’ll get it done. The point is, that just like every other software system you’ve seen, FitNesse is a collection of historical compromises. The architecture shows the scars of many decisions that have since had to be reversed or deeply modified.

What does this have to do with CRAP? Simply this. The battle scarred architecture is something that will never really go away. I can stop the bleeding, and disinfect the wounds, but there will always be evidence of the battle.

That scarring makes the system hard to understand. It complicates the job of adding features and fixing bugs. It decreases the effectiveness of the developers who work on FitNesse. And though I work hard to massage the scars and bandage the wounds, the war goes on.

But I can keep the CRAP out! I can keep the code so clean and simple at the micro level, that the poor folks who try to make sense out of the macro scale aren’t impeded by huge deeply nested functions that aren’t tested!

Think of it this way. CRAP is disease at the cellular level. CRAP is a rot so pervasive that it can infest every nook and cranny of the system. My system may have scars, but it’s not diseased! In fact, despite the evidence of battles long past, the FitNesse code is very healthy.

And I aim to keep it that way.

Comments

Leave a response

  1. Avatar
    asdf about 5 hours later:

    you are misusing iff :/

  2. Avatar
    yachris about 14 hours later:

    @asdf—how so? I’ve always understood that ‘iff’ expands to ‘if and only if’, which makes sense in Uncle Bob’s sentence.

  3. Avatar
    Bjørn Sønsteby 1 day later:

    How do you keep the crap factor low on business objects?

    If I have an object designed for holding patient data, typically used for sending data to the database layer or some OR-mapping entity class, this will largely be composed of properties with get- and set-methods, and a few of them might have simple logic, thus driving the cyclomatic complexity up. Do you just test the hell out of it to keep the crap factor down?

    This patient class may not be the SRP-purists favourite class, but dividing this type of class into smaller ones will only cause more greef when I need the entire Patient object as input parameter to a method. Another problem emerging when making business objects comply with the SRP is that introducing several more specialised patient objects will probably force me to increase the number of parameters for most functions, which is also a bad thing. So, do I have it all backwards, or is there some special principle for business objects?

  4. Avatar
    Morgan 1 day later:

    At what CRAP number is a method considered a crappy method?

  5. Avatar
    Sebastian Kübeck 2 days later:

    Bjørn,

    as a first step, you cold try to refactor the patient class into an inheritance chain. That way, you can increase cohesion AND preserve the interface by passing the bottom class around. That way, you don’t need to change the clients. In a further step, you could figure out which client uses which methods of the bottom class, change access to classes up the chain and finally refactor the inheritance chain into a tree. I have done this a couple of times and it worked pretty well. In my experience, those kinds of classes you mention tend to get bloated quickly and the sooner you step in, the easier it is to break up the class.

    You might also have a look into Michael Feathers’ book “Working Effectively with Legacy Code” and Joshua Kerievsky’s book “Refactoring to Patterns” for further information.

  6. Avatar
    Bjørn Sønsteby 2 days later:

    Sebastian, Thank you for the tip, I’ll check out the books mentioned.

    About the inheritance chain, I must admit I am sceptical. This is probably because I have seen the results of inheritance-mania at the previous company I worked at. They had migrated from java to .net, and still had some maintenance responsibility of the java code. Most of that code was written over a period of 10 years, and most of those 10 years were part of the “cowboy era” of the company. Long story short: I don’t think I’m lying to much if I estimate that you could find anything from 2 to 8 levels of inheritance. Refactoring, adding new features or introducing new developers to the code were all daunting tasks.

    However, I do agree that inheritance, used with caution, is one possible solution to this particular situation. Any other suggestions?

  7. Avatar
    Sebastian Kübeck 3 days later:

    Bjørn,

    you can turn everything into a nightmare if you try hard enough ;-). However, inheritance (+delegation) helped me with the problem you mention. If you need further information you could place your question at stackoverflow.

    Good luck!

  8. Avatar
    unclebob 5 days later:

    When coverage is 100%, Crap == CC. If you have simple logic in your business object, then CC will be around 3 or 4. So Crap will be very low. So, yes, test the hell out of it.

  9. Avatar
    chrisb 8 days later:

    We need CRAP4.net

  10. Avatar
    Jon Bettinger 8 days later:

    I really enjoyed this bit: just like every other software system you’ve seen, FitNesse is a collection of historical compromises.

  11. Avatar
    ??? ???? about 1 month later:

    ?? ?? ? ??

  12. Avatar
    ????? ???? ?????? about 1 month later:

    “I can stop the ??? ??? bleeding, and disinfect the wounds, but there will always be evidence of the battle.”

    that’s always true. ?? ? but it is out job to ease the pain on ourselves.

  13. Avatar
    xex 6 months later:

    I really enjoyed this. I do agree that inheritance, used with caution, is one possible solution to this particular situation

  14. Avatar
    xex 7 months later:

    i love

  15. Avatar
    xex 7 months later:

    i love

  16. Avatar
    xryh xex 8 months later:

    really enjoyed this. I do agree that inheritance, used with caution, is one possible solution to this particular situation

  17. Avatar
    Easy Date 10 months later:

    Clean code is most important these days

  18. Avatar
    Kooba Handbags 11 months later:

    Living without an aim is like sailing without a compass. with a new http://www.handbags4buy.com/ idea is a crank until the idea succeeds.

  19. Avatar
    FLV extractor 11 months later:

    come to have a look it is really good

  20. Avatar
    Rakennekynnet 11 months later:

    Living without an aim is like sailing without a compass

  21. Avatar
    http://linkbuilding1000k.com 12 months later:

    Thanks for the information. They have been workign hard on the project. Now is the time to enjoy the result.

  22. Avatar
    view virtual trade shows and trade fairs online about 1 year later:

    BusinessGlobal.com brings trade shows and fairs online with it’s state of the art trade exhibition platform. Visit today to view virtual expos online from the comfort of your own home.

  23. Avatar
    Skip Hire about 1 year later:

    Skip Hire, the number name.

  24. Avatar
    jewellery about 1 year later:

    I like This site! Thank you for your information

  25. Avatar
    nba jerseys about 1 year later:

    Living without an aim is like sailing without a compass

  26. Avatar
    Hermes Birkin about 1 year later:

    Money can`t buy Happiness? Whoever said that doesn`t know where to buy.Hermes Birkin Buyhermesbirkin offers the high quality Hermes bags and services.Hermes Belt No matter it is the classic Birkin bag, or the Kelly and Lindy bag,Hermes Purse or the latest new designs, you can find them here. Just selecting one, you will be the next Victoria in the street. – Comes from Shuna Sun

  27. Avatar
    Rangemaster 110 about 1 year later:

    a friend of mine uses FitNesse if I remember it rigt

  28. Avatar
    Tenant Screening about 1 year later:

    This is such a good information. Thanks for sharing this to us.

  29. Avatar
    http://www.hats-trade.com/monster-energy-hats-c-26.html about 1 year later:

    Recently established in 2006,http://www. hats-trade.com is the website of a company that has been in business in the Chinese market for about 3 years.We are hats manufacture in china, Our company specialize in supplying new era hats, Monster Energy Hats,dc shoes hats,red bull hats,famous hats,jordan hats,etc. We pay attention to our products quality and service.

  30. Avatar
    Health Care and Beauty about 1 year later:

    Pretty fantastic post. I found your blog and wanted to say your information seems legit. Will keep informed.

  31. Avatar
    http://www.hatmvp.com about 1 year later:

    Do you want to be more fashion, more charming,just do a little thing. A exciting purchasing is ready to go! Just pay attention to. We are specializing in providing new era hats wholesale,new era caps ,one industries hats,rockstar energy hats,http://www.hatmvp.com ">Monster Energy Hats which would be your final choice. Just do what you want alonging with your active heart. Our website is persisting on best customer service. Please come and enjoy it! you can find more such article in http://www.hatmvp.com

  32. Avatar
    http://www.caps-store.com about 1 year later:

    Best new era caps, new era hats wholesale,Monster Energy Hats,Dc Shoes Hats,red bull hats,New Era Caps,NFL Hats ,Famous Hats ,new era 59fifty hats,jordan hats and coogi hats,etc are in stock now. Our site provide first-class service and reliable quanlity garantee,do not hesitate to shake hands with us and go with the tide as soon as possible!

  33. Avatar
    http://www.caps-hat.com about 1 year later:

    We wholesale hats at competitive price,providing a huge range of hats with different brand name,such as coogi hats, polo hats,Jordan hats,famous hats, red bull hats, new era hats, etc.You can buy cheap hats. Welcome to visist here ?http://www.caps-hat.com

  34. Avatar
    Pandora about 1 year later:

    with their own execution of SuiteSetUp and SuiteTearDown.

  35. Avatar
    http://www.blacktowhiteiphone4.com about 1 year later:

    Is white iphone 4 available right now? Cuz my friend told me he just got the white iphone 4 panel. But i haven’s seen it sold in my area. What’s wrong?

  36. Avatar
    Silicone Molding about 1 year later:

    Mold making is the core business of Intertech (Taiwan). With world level technology, Intertech enjoys a very good reputation for making Injection Mold and Plastic Moldsfor their worldwide customers.

  37. Avatar
    levitra 10 mg about 1 year later:

    Glad to come across this article. Thanks for taking time to write this post. really good ideas.

  38. Avatar
    Movies Cheap about 1 year later:

    Wondershare Video to DVD Burner will not only copy movies to DVD from LimeWire to improve your viewing experience, but also save much of your precious hard disc space.

  39. Avatar
    iPad to mac transfer about 1 year later:

    Thanks for shareing! I agree with you. The artical improve me so much! I will come here frequently. iPad to Mac Transfer lets you transfer music, movie, photo, ePub, PDF, Audiobook, Podcast and TV Show from iPad to Mac or iPad to iTunes.

  40. Avatar
    Hydraulic Fittings about 1 year later:

    Classic exposition, I have also mentioned it in my blog article. But it is a pity that almost no friend discussed it with me. I am very happy to see your article.

  41. Avatar
    Criminal Records about 1 year later:

    My system may have scars, but it’s not diseased! In fact, despite the evidence of battles long past, the FitNesse code is very healthy.

  42. Avatar
    Tenant Screening about 1 year later:

    It’ll take some time, but I’ll get it done. The point is, that just like every other software system you’ve seen, FitNesse is a collection of historical compromises. The architecture shows the scars of many decisions that have since had to be reversed or deeply modified.

  43. Avatar
    http://www.caps-jerseys.com about 1 year later:

    caps-jerseys.com wholesale monster energy hat,red bull hat,MLB baseball hat,MLB jerseys,NBA jerseys

  44. Avatar
    http://www.hatsvip.com about 1 year later:

    Establish relationship with domain for new york yankees hats .

  45. Avatar
    cable ties about 1 year later:

    i recommend this article to my friends.

  46. Avatar
    Sunglass about 1 year later:

    Buy sunglass

  47. Avatar
    Yalova Emlak about 1 year later:

    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.

  48. Avatar
    Seobaglyak about 1 year later:

    thanks for writing this article :) :)

  49. Avatar
    Mulberry Outlet about 1 year later:

    I can’t believe it. There is so great post. Thanks a lot for share.

  50. Avatar
    mulberry bags about 1 year later:

    THE FIRST TIME I saw the White House was in 1984. mulberry bags I had just graduated fromcollege and was working as a community organizer out of the Harlem campus of theCity College of New York. President Reagan was proposing a round of student aid cutsat the time, and so I worked with a group of student leaders—most of them black,Puerto Rican, or of Eastern European descent, almost all of them the first in theirfamilies to attend college—to round up petitions opposing the cuts and then deliverthem to the New York congressional delegation. mulberry alexa bags It was a brief trip, spent mostly navigating the endless corridors of the RayburnBuilding, getting polite but cursory audiences with Hill staffers not much older than Iwas. But at the end of the day, the students and I took the time to walk down to the Malland the Washington Monument, and then spent a few minutes gazing at the WhiteHouse. mulberry antony bags Standing on Pennsylvania Avenue, a few feet away from the Marine guardstation at the main entrance, with pedestrians weaving along the sidewalk and trafficwhizzing behind us, I marveled not at the White House’s elegant sweep, but rather atthe fact that it was so exposed to the hustle and bustle of the city; that we were allowedto stand so close to the gate, and could later circle to the other side of the building topeer at the Rose Garden and the residence beyond.

  51. Avatar
    Google about 1 year later:

    We also carry an assortment of bird feeders, bird baths and other accessories welcomWood Pellets Fuel

  52. Avatar
    cheap baseball hats about 1 year later:

    PAs a very active manufactures, we develop new Oakland athletics hats designs nearly every month, If you have interest in it, it’s my pleasure cheap baseball hats to offer news to you regular.

  53. Avatar
    liweifeng about 1 year later:

    I am very happy to see your article.thank you for your sharing.Living without an aim is like sailing without a compass. Discount Sunglasses Online

  54. Avatar
    okey oyunu oyna about 1 year later:

    i love it.

    internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.

  55. Avatar
    http://www.wayshoes.com/ about 1 year later:

    I know,as a social people,I must study as possible as I can,then i can learn a lots from you website.thanks.

  56. Avatar
    Best Lip Moisturizer about 1 year later:

    “CRAP is a metric that is applied to each function in the system. The formula for CRAP is: CRAP = comp(f)2. X (1 – cov(f)/100)3. + comp(f)” It have helped me a lot. I have confusion aabout this logic.

  57. Avatar
    cheap brand watches about 1 year later:

    Good writing, this article bring me a lot. Your blog is great, thanks for sharing.

  58. Avatar
    fioricet about 1 year later:

    Great and impressive blog you got here. It looks like you made a big effort in order to get that information and put it in writing. thank you.

    _____ fioricet2u.com – Buy Fioricet Online

  59. Avatar
    shoes christian louboutin about 1 year later:

    There were SO many tiny donations, but they really added up fast! Thank you!

  60. Avatar
    retrojordanshoessale over 2 years later:

    I like this concept. I visited your blog for the first time and just been your fan.z

  61. Avatar
    Jewellery over 2 years later:

    6468464

  62. Avatar
    lose thigh over 2 years later:

    intresting CRAP discussion

  63. Avatar
    http://www.goodwomenshoe.com/ over 2 years later:

    Which brand bags you like best,what about burberry,that you know ,Burberry outlet online will give you the high quality and cheap price.Burberry outlet for you .

  64. Avatar
    replica Oakleys over 2 years later:

    A man walking in the street, I remembered that I bought her that mobile glasses, in fact also pretty good

  65. Avatar
    http://www.fakemaccosmetics.com over 2 years later:

    Good post,thank you for your share

  66. Avatar
    Emily over 2 years later:

    Hi buddy, your blog’s design is simple, clean, and I like it. I really enjoy reading your blog popular distributed: a good article waiting for you!<a href=”http://www.fakelvbelts.com”>Fake louis vuitton belts< /strong> Louis Vuitton sale< /strong> louis vuitton belts sale< /strong> cheap louis vuitton belts< /strong>

  67. Avatar
    http://www.cheapmulberrysale.com over 2 years later:

    This specific earlier On the, Aim for produced its almost all envisioned collection nonetheless: Mulberry for Target. Even though this specific Uk company usually offers its luggage near to the $1000 budget, men and women can now obtain its consider considerably a reduced amount of from Aim for shops. The product quality is actually clearly considerably several, nonetheless pretty much essentially obtain what we pay for. By way of example, Cheap Mulberry Shoulder Bags always employs 100% set as well as patent set, even so the Mulberry with regard to Aim for employs PVC. Also, just how it really is established in addition to sewn along isn’t since excellent since the real thing. Post don’t know when it’s that content that is certainly more difficult to sew along, even so the original Mulberry Shoulder Bag might seem quite a specific set of in addition to demanding.

  68. Avatar
    Crystal Jewellery over 2 years later:

    Great post! Nice and informative, I really enjoyed reading it and will certainly share this post with my friends . Read everything about the gold history and its complex and interesting facts.

  69. Avatar
    beats by dre store over 2 years later:

    Also, just how it really is established in addition to sewn along isn’t since excellent since the real thing. Post don’t know when it’s that content that is high quality headphones new design headphones

  70. Avatar
    canada goose coat over 2 years later:

    When it comes to feather dress, what appears in your mind? Which kind brand of down jacket do you like prefer? Though there are many down jackets for you to choose from, on the word, which one you really enjoy? I want to say that canada goose coats is really your best choice. I believe you can’t agree with me any more. When you take the quality into consideration, you will find that it is superior to any other kind of coat. Besides, discount canada goose jackets is a world well-known brand, which has gained high reputation in the world, which has accepted by our customers and some organization. Because of its high quality, some of our loyal customers have promoted it to the people around them. In their opinion, it is good to informing others to know it. Recently, Canada Goose Trillium Parka is on hot sale. What I have to inform you is that all the products there are made by hand, so they are elaborative and elegant enough. It is really beautiful once you dress in. So, if you are a lovely girl or woman, go to the store to buy one for you. You will appreciate it that you have such a coat.In addition, they also have any other products like canada goose Gloves and canada goose jacket supplier.Hope your will like its!

  71. Avatar
    http://www.goahats-business.com over 2 years later:

    I enjoy reading the report, too. It?s easy to understand that a journey

    like this is the biggest event in ones life.

  72. Avatar
    ysbearing over 2 years later:

    Slewing bearing called slewing ring bearings, is a comprehensive load to bear a large bearing, can bear large axial, radial load and overturning moment.

  73. Avatar
    christian louboutin over 2 years later:

    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:

    Color: Coffee
    Material: Suede
    4(100mm) heel
    Signature red sole x

    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.

  74. Avatar
    beats by dr dre over 2 years later:

    A university studentbeats by dr dre caught by the enemy, the enemy tied him at the poles,just beats solo headphones purple and then asked him: say, where are you? You do not say it electrocuted! Scheap dr.dre beats studio headphones balck/yellowtudents back to the enemy a word, the result was electrocuted, he said: I am TVU.Hot sale beats by dr dre pro headphones

  75. Avatar
    GHD over 3 years later:

    http://www.ghd-pink-orchid.com ghd straighteners http://www.nzstraighteners.net ghd http://www.ghdplanchas-espana.com ghd planchas http://www.ghdspecials.com GHD South Africa

  76. Avatar
    iPhone contacts backup over 3 years later:

    Good idean.right?

  77. Avatar
    Discount Louboutin Shoes over 3 years later:

    Every women always has Christian Louboutins Wedding Shoes turn of fame but it also has its own goodbyes.

  78. Avatar
    fake ray bans over 3 years later:

    Welcome to fake raybans store online!Our company is fake ray bans manufacturer & supplier,our company also supply fake ray bans .we have been in designer sunglasses for 8 years.there u can get the cheapest price in our company sites,waiting for u visiting.Fake ray bans sold in our company.our company’s .fake raybans let you enjoy your life withour paying high prices,and our daily necessities have been sold all over the world for many years and influenced by the customers’ approval.our company is your first choice.

  79. Avatar
    Mallorca properties over 3 years later:

    I will follow your advice… I will try to optimize the code.

  80. Avatar
    Zymessence over 3 years later:

    I also wish him good luck to defend his gold medal. I definitely enjoyed every little bit of it I have you bookmarked to check out new stuff you post.

  81. Avatar
    lipozene over 3 years later:

    This is what I have been searching in many websites and I finally found it here. Amazing article.

  82. Avatar
    mbtshoe over 3 years later:

    Australia Beats By Dre Studio dr dre beats headphones beats studio beats pro beats solo hd pro headphones music Official store Monster Beats By Dre Pro

  83. Avatar
    Microsoft Support over 3 years later:

    An insightful post… There are still reasons to pay attention to efficiency when writing code… and As computing resources continue to grow, efficiency falls further behind another concern when writing code, though… That concern is the cleanness of the code itself… Microsoft Support

  84. Avatar
    air mens shoes over 3 years later:

    actual accepted are primarily bought by collectors falling aural the area of collectors such as civilian war fanatics American history followers. A nice archetype would be that of the Waltham watch

  85. Avatar
    cheap air shoes over 3 years later:

    which was of the aboriginal time pieces every to be produced in accumulation manufacturing. The best way to be audible the actual accomplishment date of a partic. Snapback ular watch is to analysis

  86. Avatar
    Coach Factory over 3 years later:

    Very good to read your most informative article. Its very informative and well written also.

  87. Avatar
    bladeless fans over 3 years later:

    Clean Code and Battle Scarred Architecture 86 good post27

  88. Avatar
    louboutin sales over 3 years later:

    Clean Code and Battle Scarred Architecture 87 hoo,good article!!I like the post!134

  89. Avatar
    cheap adidas f50 over 3 years later:

    She kept true to the party’s nationalist theme, but, in an Cheap Adidas Adipure attempt to widen her electoral base, vowed to tone down the xenophobic legacy of her father. http://www.cheapadidasf50.com/ CF

  90. Avatar
    movers in Dubai over 3 years later:

    Not only is this post insightful, but well-written and articulate too. Thanks again!

  91. Avatar
    mydollargate over 3 years later:

    Not only is this post insightful, but well-written and articulate too. Thanks again!

  92. Avatar
    Christian Louboutin spike shoes over 3 years later:

    Do you judge a person based on his or her shoes? Perhaps you do. Christian Louboutin spike shoes When I see someone wearing cowboy boots, immediately I will assume Christian Louboutin peep toe ankle boots he comes from Texas and he even rides a horse. When I see a woman Christian Louboutin satin peep toe wearing high heels, I assume she must be a shopping lover and a fashion pursuer.

  93. Avatar
    hermes kelly brown over 3 years later:

    Finding the latest trends for boys can prove a little difficult as many mums will know?

  94. Avatar
    Injection Mold over 3 years later:

    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.

Comments