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)
- Our Goals for the JPedal Java PDF Library SDK in 2017 - December 16, 2016
- Annotations in PDF Files, what are they and why use them? - July 27, 2016
- What is XMP metadata and why it is useful - June 7, 2016
- Improving our JUnit tests - August 6, 2015
- Improving Our Java PDF Printing Examples - July 14, 2015