As you write more programs (and perhaps learn new languages to write them in) you will gradually build up a collection of code that performs a wide variety of tasks. In some cases this code may never actually make it into a program because it turned out that it didn't help solve the problem on that occasion. While some of this code may have been developed for an employer where they own the copyright on the specific code used, you should attempt to keep copies of as much of the code that you write as possible.
There are no unique problems to be solved in programming. In every case a given problem will share something in common with other problems. If you have never worked on any of these related problems then this isn't going to help you as much but if you have solved problems that have something in common with the new problem then chances are that somewhere in all the code you have already written there will be something that will help with solving the current problem. The particular code may have been written in a different programming language from the one you are using for this project or it may have been written for a past employer so that you are going to need to rewrite the code but you have already solved the particular problem once and so can easily rework your previous code to suit the current situation.
The problem you are now trying to solve may be just sufficiently different from a prior problem that some of the code you wrote at that time and abandoned because it didn't end up helping to solve that problem may be just what you need to solve this problem.
For anyone who has been writing code for even a short time there will likely be something that they have already written that will help in some way with the current problem. At the very least the code provides you with a library of solutions and partial solutions to problems that can give you ideas as to how you might go about at least partly solving the current problem. If you think of two different ways of dividing the original problem up into three smaller problems and you already have a solution for one of those smaller problems then choosing the alternative that makes use of that solution means that you are already part way toward solving the problem and it is worth spending at least some time trying to solve the other two smaller problems that together with that code will solve the original problem first before considering the alternative three where you don't yet have a solution to any. Of course it may turn out that solving the three smaller problems of the other alternative is easier than solving the two in which case you will end up not using the code you already have but then you are no worse off than before.
Of course when you are first starting out you will not have any code of your own from prior problems. Of course there will be plenty of code written by others that you will have access to view. Where you don't have a code solution to a particular problem yourself but you have access to someone else's code that does then that puts you closer to solving the problem. Of course you may not be able to use the exact code that someone else has written because they own the copyright and do not grant permission for others to use their code but you can still examine their code to see how they solved the problem in order to then write your own solution. In fact even where you do have permission to use someone else's code you should still examine how their code works and make sure that you understand it properly as this is the only way to be certain that the code does solve the right problem and also to ensure that you will be able to maintain the code in the future. The one thing you need to avoid though is using someone else's code when you don't understand what it does - in that situation you will not be able to be certain that the code actually does solve the problem that you need it to solve.
By making use of your growing library of solutions to see what might be applicable to the current problem you can reduce the size and complexity of the problem that you need to solve. If you are really lucky you may even work out a way to combine several pieces of code that you have already written so as to solve the entire problem with the only new code being to link several pieces of code you had already written together so as to solve this particular problem.
This article written by Stephen Chapman, Felgall Pty Ltd.