Friday, September 10, 2010

Thoughts on Code refactoring

Well I can assure every one that the title is definitely misleading, its not thoughts but just a thought right now but I plan to add more(assuming I will be able to overcome my laziness .... ahhh... how badly i need the thoughts to text converter...)

Anyways a friend of mine recently looked at a code I had written almost 6 months back and observed that a lot of code is repeated. Well I sure tried to justify myself that there are subtle differences and thats why duplicate code is there but when I think more about it I guess the main reason is because enterprise code is not written in a single day or by a single resource. I think both these reasons have led to a lot of duplicate code and lot more TODO's and FIXME's in the code. I just wonder that whether we should plan some time to have these resolved also. Sadly in enterprise software code you hardly get the time to look back at your code get a chance to fix it. I so badly want to refactor the code I have written, I swear I do, but then will my company give me a chance to do this once the code has gone to production, the answer is a definite no. Well I can write as many test cases as I want to ensure that refactoring won't break anything, but still the risk to refactor is still too large. I guess I will have to agree that write less but write clean, sadly time is never with developers writing enterprise code.

In the end I think all this is good learning and will help me in my next project.

No comments: