Wednesday, November 16, 2011

When do we get time to clean our code mess?

When do we get time to clean our code base?

This was the question asked by one of my colleagues to the Executive Vice President in the all hands meeting.

The Executive VP heard it like code mess (and another VP corrected it). He said something like, come up with a plan with the manager and the director, and he would consider that etc.

The following are my thoughts on the same.

Before asking the time for cleaning up the code base, I have few questions.

Did you write clean code yesterday?
Are you writing clean code today?
Will you be writing clean code tomorrow?

If the answer is No, then there is no point in asking extra time to clean up the code base. If we are not going to write clean code in our every day tasks, and asking separate time to clean the code base, there is absolutely no use, and it is just waste of the time, resources and money. First we should concentrate on writing clean code everyday, and then we should think of cleaning the existing code.

In any business, it is of no use to spend some extra time to clean some code base, unless we are 100% sure that, the code need to be changed soon with short dead lines, and also before that, we will not get any feature which requires re-writing of that. If the code is going to be re-written soon, then there is use of cleaning it now. We can directly re-write it later on. Whenever we get the change request in a component, at that time, we can try to fix the design/code of that component. Only, if we are sure that, the time that is given to those change requests is not enough with the existing design, we should fix the design now. Otherwise, there may be no use of cleaning it now.

If we are modifying a component, then the modified design should be in such a way that, all the parts that you are touching and it's integration with other parts would become very clean after that. If you are writing code, not only the exact parts that you are touching, but, all surrounding parts of the code also should be cleaned.

If you are changing a method as part of a bug fix, then may be you should look at the entire method and it's usage, and see whether you can rewrite the method in a very efficient way. If you are adding a method in a class, may be, you should look at redesigning of few methods, so that, the class would become clean.

Whenever any developer changes any code, if they look at the high level picture, and modify the code/design accordingly rather than just implementing that feature alone without bothering anything else, then within couple of months/years (depending on the size of the project), the entire code base becomes very clean.

Generally, no business person would give dedicated time to clean the code, unless, they are 100% sure that, the code would be maintained a lot and will not be re-written. They may also give time, if they have deep pockets. If they have deep pockets, probably, you can ask for salary raise first.

Courtesy: Shawn Smith (Who has shown me the difference between fixing a bug by a developer and a Distinguished Engineer. If he fixes a bug, then only another distinguished engineer can fix in such a clean way).

No comments:

Post a Comment