Code Reuse

What is code reuse?

"Code reuse" is pretty self-descriptive; it is the practice of 
using already-existing code to perform a new function or to act in 
a new environment. The concept is broad however, and can apply to
everything from cutting-and-pasting bits from last week's code to 
creating an application programming interface (API) and putting useful
functions into a library for external use.

Why reuse code?

Code reuse increases productivity. If someone on project "A" has spent several weeks writing bug free code that handles socket communications, and you have the same or nearly similar need for the project you are working on, why spend another two weeks re-creating the code yourself? Reuse the working code.

Hints for code reuse

Before attempting to solve the problem yourself, search the open source software sites for code or libraries that you can use for free. Here are two very good sites:
The Jakarta Site
SourceForge
The code you find here is usually well written and bug free. There are exceptions, but usually if you pick a software version that has been out for some time and stable you will not have a problem.
If you choose to reuse code within your own company things become a little more difficult. First how do you learn what is out there? Usually the only way is by word of mouth. Then even if you find some code that solves your problem, it may not be exactly what you need, and it may not be bug free. In either case you will have to modify the code before you use it.
It is a difficult job to decide which takes more time, writing the code from scratch so it is just what you need, or searching for existing code that may have to be modified and debugged. You should at least look at the sites listed above and ask other software developers in your company for a solution. This is better than spending several months creating software that you could have downloaded for free.
Finally, if you have written a software solution that you think could be used by others, consider distributing it within your company or if possible contribute to the open source sites listed above. Writing a well documented and well designed library is difficult so be aware of what you are taking on. Remember if you distribute your code to others you are taking on the responsibility of providing bug fixes and upgrades. In addition your API should be professionally designed and abstract enough so that many different applications can use it.

Documentation

Wikipedia: code reuse