Plan your coding
When starting up a big project og an advanced function, having a pre-made plan will often save you a lot of time. Even though everything seems clear at first, you may have forgotten or will forget something crucial while writing.
A good plan should contain information about your coding approach, when the different variables are known and unknown, and what the output of each code block is supposed to be. Knowing all this information in advance will help you locate difficult sections of your code, as well as preventing unnecessary code or rewriting.
Write useful comments
Commenting while writing will always help you out in the long run. Your code may seem very simple and self explanatory at the time of writing, but to someone else, or yourself in three months, it is not necessarily that simple. Write meaningful, single line comments for vague lines, and more detailed descriptions for more difficult sections.