May 04 2008
Code reuse in web context
Hello everyone!
I’ll write today about a code reuse, maybe one of the most interesting controversy of the IT industry. I have three questions that I’ll try to answer in this article:
- Why it is good to reuse code and why it is bad?
- How and when can we reuse the code?
- How to minimize the problems that may appear?
We noticed a general tendency of teams to accumulate and reuse code. Such a practice reduces the time required for development and speeds the delivery. Client will be happy, the management will be happy and the team may proceed to another project. Stop! It sounds great but it isn’t.
Problems that may appear with this approach:
- If the reused code is not enough tested, errors from previous applications will be duplicated in the new application
- Following the “let’s reuse the code” idea, developers will try to adapt the old code of a module to meet the requirements for the new solution and not to find the best way to develop that module in accordance with the clients necessities.
- If there are some new developers in the team, they will spend important time to understand the concept of the old code and to find the solution of how to integrate it in their code. In many situations, that time is bigger then the development of a brand new module.
- The new module will not be intensive tested because: “Hey, it was already tested in the old applications!”.
All those problems can be minimized. To reduce the probability of bugs perpetuation, you should have a quality assurance department that will identify all bugs through automatic testing. Also, through this approach, team manager will have the possibility to say: “This module meets the clients requirements”. Learning curve of understand the concept of the old code is reduced when the team follows the same standards, has the same development environment and a communication channel exists between the author of the code and developer that use it. Maybe the result is not “the best module money can but”, but will it will work pretty well in a production environment.
Working with code libraries, internal frameworks that simplifies the development process must be done under a very well controlled environment and managers should always have the following question in mind: “How many time I will save reusing that piece of code?” And they should always consider that testing, implementation and delivery process is an important part of the project. Delivery of a module with reused code with errors will require much more time to debug.
Developers are not very confident with code written by other developers. They have to learn the frameworks very well, they have to deeply understand the concepts and somehow take the ownership of that piece of reusable code.
Code libraries and frameworks must be kept alive. Code should be changed when someone finds a better approach, if the industry requires a different approach or the development environment has been changed (new compiler or interpretor version, new standards etc.)
You may ask why the title is “Code reuse in web context” and I didn’t mentiond about “web”. Well, I’ll do it right now.
In web development environment is much more complicate to reuse code because we can hardly find two websites that require the same functionality. Even there are a lot of frameworks for web development, all of them has the same problem: doing much more then required. That slows down a website build on top of such a framework. Web developers should reuse small parts of software already written and should try to reuse the concepts and the practices.
I prefer to reuse small pieces of code but every time I try to adapt them to client requirements. It doesn’t makes sense to rewrite from scratch a charting library if you already did. But it must be filtered and any code that is not used should be removed.
As a conclusion: before thinking of how to reuse the code, think about how to organize your code and how to set-up a deployment and implementation process.
