Everywhere I go these days I find recycling going on. We are told to reuse as much as we can. This may be a great and noble thing for the environment. Even before the recycling craze we have been encouraged to recycle code. Why reinvent the wheel?
Maybe because that wheel was designed for a car and I am building a bicycle.
Please don’t get me wrong, re-usable code can be great. The blind copy and pasting of code is what I am against, it can become a bad habit. As I’m writing this I feel that I am slightly bitter about the topic, that is because I have been guilty of this in the past.
There are many advantages to writing the code to be re-usable and then re-using it. Surely we all know them, the code has been fully tested in the past, it cuts down on development time and fixing any bugs that may appear in one place can also resolve related issues elsewhere. These are just a few of the advantages.
The problem is there are also disadvantages that I rarely see mentioned. For instance the code being re-used often starts life doing one task. To then use it elsewhere requires adjustments. After using the same code in several places it can easily become too complicated with multiple conditions for specific cases. Another issue that can arise is that the code that is being re-used can increase in complication until unintended results or bugs may appear. As the code is used in multiple places you could end up with multiple areas of the code demonstrating issues. It is also all too easy to start by duplicating code used elsewhere to achieve similar functionality to find you have spent more time converting the code than it would of to write it from scratch, quite often in these cases the final result is so different the code is nowhere near the original.
At the end of the day, no matter how many disadvantages there are, re-using code is too advantageous to simply ignore. The majority of the disadvantages are simple things that can be prevented with proper handling of code and a bit of thought about how the code is being used.
So, what is your opinion of re-usable code? Ever found it has been ill advised?
Latest posts by Kieran France (see all)
- Removal of features – Right click find functionality - August 5, 2014
- 1 Listener to rule them all - July 15, 2014
- Grey box appears within display area - June 24, 2014
- How to reselect elements in a JTree - June 3, 2014
- 3 ways to help keep you focused - May 7, 2014