2008-09-23

Coding to the core

I remember in my first job, I have joined a project that was based on an infrastructure built by some other developers, and they were not working in this project anymore.

During my first days of training, I was told "never to touch" that infrastructure, and it made me write a funny poem about that on our whiteboard.

I was always encouraged to find other workarounds rather than modifying the infrastructure. And when it was really needed, it has to be kept minimal, done under close supervision, treated with high suspection, and always thought of first as the source of every bug that appeared later.

And in the following years, I started to read about good software design, refactoring, so I was always leaning toward "butchering" old code, but I always depended on my own manual testing to verify that I didn't break anything in my refactoring "rides". Manual testing was good for about 90% of the times, but there were few cases that skipped me, and hence I got that look "we told you not to touch it!!". I was much experienced then, but it didn't give me the right to try something that was considered a "taboo" before.

I still remember how terrified was one of my junior colleagues when I proposed adding a method to a base class instead of adding it to all subclasses.

Today, one of my colleagues asked me about a problem, and after 5 or 10 minutes of discussion, we found out that one of the solutions is to add the new required functionality to the base class (may be it was not the best solution, but it was better than the one she implemented). And then I wondered why didn't she thought of it in the first place, and as I expected, she didn't want to "touch" the base class although it was the straight forward solution, and thought of workarounds. And I was happy I encouraged her not to fear the "core".

My point is, why do we keep building barriers to improvements? development is an innovative process, and it is the duty of seniors to encourage juniors to learn and try. In addition, we have all the tools that help us in our mission; source control, refactoring helpers, clone detectors, code analysis, unit testing, and more. And believe me, the cost of maintaining a badly designed project, is much much higher than the cost of a bug that might skip from the core.

I have also to stress that refactoring with freedom has to be coupled with extensive Unit Testing and Code Coverage, but that might be the topic for anothe post.

No comments: