Do a very clear design or blueprint first which includes a test plan. Identify teh algorithm, all inputs, and all outputs.
Start from the top down and write the basic program.first and then build on that.
Put in many comments.
Do not make any program too large. Make one fairly small main driver program that calls smaller functions or subprograms..
You may need to write a test driver program just to get it fully tested.
Most companies have developer guides and I have written one for a company. There would be many more items listed but much depends upon the computer languages and databases being used.