Monday, September 21, 2009

On why I choose to invest in clean code

Lately there is a lot of talk about "Clean Code". This is in part due to Robert Martin's recent book by the same name. I've heard people come up with idealistic reasons to embrace clean code practices. That all well and good, but when you're face with a team who does not share your conviction, this can be difficult.

Why should I invest in clean up code if I cannot keep the whole of the code pristine?

Well I continue to write clean code and to re-pass the broom over the same floors I have previously swept because if I dont it will deteriorate into a real bordello.

I continue to clean up because every effort I make to figure some tangled mess out is an effort I do not want to repeat later. The two hours I spend trying to figure out the purpose of a dozen poorly-named classes are hours I do not want to re-live. The next time I pass through this code I want my previous insights to jump out at me, not hide behind the same mess I dug through last time.

I continue to clean up along my path because I hope that the next person (however clean-conscience they may or may not be) does not get slowed down by the previous mess. This person is my team-mate, and the success of my current commitments is dependent on them. Anything I can do to save them wasted time benefits me.

I continue to write clean code and clean up the problems that cross my path because that same team-mate may waste my precious time asking me questions that I could otherwise have answered directly in the code.

This seemingly futile exercise in clean up is all geared at saving me wasted time on a daily basis.

Why do I chose to invest in clean code? Because I'm lazy.

2 comments:

mberube said...

Clean code is indeed important and makes you save time in the end.

But for me, the real reason to do it is pride. Pride in work well done. Satisfaction that I did every thing I could to make my intent clear.

Erik said...

I take pride in code well written. My running concern is that many people stop writing clean code if they feel that they are fighting an uphill battle.

My point is that there are practical reasons as well as personal reasons to keep the code clean.

thanks for reading!