Wednesday, June 11, 2008

Resetting the 'Shitty' Counter

Again and again I hear the following phrase: 'This code is so bad that it has to be rewritten'. That statement is right in some cases. Even though I prefer to refactor, there are situations were it does not make sense any more. Most code bases can be salvaged with major and persistent refactoring efforts. Over time your refactoring skills get better and better and more systems are cureable but still, some cases are what they are: terminal.
What does it really mean to rewrite a system? It is the defeat of the software team. Often the existing team inherited the system, or worse they are the original authors. In either case, no team was able to make the code base more maintainable or at a minimum not to make it worse. The project lacked fundamental skills like team communication, best coding, configuration and testing practices. They failed -- the code rotted in their hands!
Next, this team decides to rewrite the system and promises to make everything better the next time. Sounds good? To me, it is more like a broken record. Why? They will repeat most of their mistakes and eventually call for another rewrite. Sure, the team learned from some of the old mistakes, but still this does not suffice to prevent another decaying code base. The rewrite means basically to 'Reset the Shitty Counter' [1].
Now your Counter is at zero, but unless you take matters in your own hands and actively manage the risks of your old mistakes your 'Shitty Counter' will slowly inch upwards. Well, ... you know the story!
How can this be achieved? There are many best practices from the agile world and even more books about those. It would be foolish for me to try to explain each of them and their dependencies and how they interact.

However, I will give you my elevator pitch:
  • Test Driven Development (TDD)
  • Pair Programming
  • Continuous Integration
  • Co-location of programmers, testers and domain experts
  • Scrum (do the Nokio Scrum Test to make sure you really do it [2])
  • Never ever change the length of your iteration
  • Determine you velocity
  • Retrospectives after every iteration [3]
From a code point of view, one should aim for:
  • Short methods (not more then 10 lines per method)
  • Single Responsibility Principle per Class
  • Low complexity (McCabe or CCN)
  • Loose Coupling and High Cohesion
  • Law of Demeter
  • Injectability (ie. Spring, Google Guice, PicoContainer)
Static Code Metrics
  • Test Coverage (use with caution unless you have many small tests)
  • Testability of Code (Testability Explorer) [4]
  • Percentage of duplicated code (CPD) [5]
These are the tools of the trade of an agile test infected code warrior. If you use those best practices on a daily basis and refactor your code mercilessly. Over time your code base will actually become better. It is not easy, it is a skill you learn by doing manually, day in day out.

[1] This term was coined by a colleague of mine
[3] Agile Retrospectives (Esther Derby & Johanna Rothman)


JH said...

dirty said...

Couldn't agree more with your list... although I fear that for the majority of the code-writing populace to take note of your wise words it will take some serious re-education; potentially with some type of hammer. I'm constantly underwhelmed by the standard of code that I come across... even in my current team, which I believe is one of the most talented that I've worked in. To do code properly takes remarkable vigilance and merciless refactoring... not something that comes naturally to anyone.

Unknown said...

Code reviews are a must ! I've found that most people make better attempts at writing good code when they *know* someone will be looking it in a code review. Crucible is an awesome tool for this !

Unknown said...

How are you using Testability Explorer? It looks like just the thing I was looking for! But after a first glance, it seems to be very command line-driven, including the reports. Have you integrated it with Ant/Cruise Control/Maven or anything like that?

If not, I'm thinking about creating something of my own...

trustme said...

This is really a nice blog, I appreciate you for telling us so nice things, thank you!By the way, if you like nike tn you can come here to choose! We have a lot of
nike tn,tn chaussures,
nike tn requin chaussures,nike air max tn chaussures.
If you want to find the shoes according to the sorts, then here you can have the informations,
we classied the shoes in nike presto,
nike air max,
vibram fivefingers,
At the same time, the vibram also offer you in our store.
You also can choose the most fashionable sunglasses here, it really can make you different from other people. We have
sunglasses,designer sunglasses,
wholesale sunglasses,sunglasses discount in USA.
They includ men's sunglasses,women's sunglasses.
So many fashion brands are for you,like Dior Sunglasses,
Emporio Armani Sunglasses,
Fendi Sunglasses,
Giorgio Armani Sunglasses,
Gucci Sunglasses,
LV Sunglasses and so on.

Unknown said...

The Tax Return Crack-Up<3>
Granted, there are usuallyMicrosoft Office 2010write-ups when presidential contenders make their tax returns available, but the coverage falls far short of the Office 2010
full court press (pardon the pun) that the Clintons have received. What's Microsoft Office 2007different now?Office 2007One possibility is that most upper middle class Democrats, and therefore most Microsoft OfficeOffice 2007 keyeditors and reporters of our nation's big papers as well as Office 2007 downloadtelevision producers, are Obama supporters who think that Hillary should hurry up Office 2007 Professionaland drop out of the race already.Microsoft outlook
Microsoft outlook 2010Whom elite liberals are pulling for really does shape political coverage in ways

teragoldonlinefsbest said...

I prefer headlines that create a little controversy, I always find myself clicking on titles that are imaginative out of curiosity. Many best players know some online game. Here useful link:Tera Gold
cheap rs gold cheap wow gold Tera account

Anonymous said...

And if you find such a friend, you feel happy and complete, because you need not worry Cheap Diablo iii Gold, Diablo iii Gold Sale your forever friend holds your hand and tells you that everything is going to be okay Diablo 3 Gold.

dte said...

The past is gone and static. Nothing we can do will change it.scarlet blade gold, the future is before us and dynamic. Everything we do will affect it rs gold, You laugh at mescarlet blade gold for being different , but I laugh at you for being the same.

Unknown said...

The GW2 Gold is obvious: to eliminate the actual podium protection. Using a bunch of buddies or even arbitrary companions will truly do well, and also here arrives Diablo 3 Gold Farming yet another "event": wipe out bandits running using the recover the cash. If you can accomplish it, below arrives a final miniseries.

ac market said...

upper respiratory tract infection treatment
upper respiratory tract infection icd 10
upper respiratory tract infection home remedies
upper respiratory tract infection causes