There are good answers here.
A big spin in your favor is the simple fact that you want to know.
Much of software engineering (which you should take with healthy skepticism, of course) is about how to do it in ways you won't regret later. One example is the use of a source code version control system. Another is dividing the code into files so it's easier to work on it piecemeal. Another is to be a stickler about orderliness - code formatting and naming conventions. The exact conventions don't matter as much as being consistent about it.
That way, when you come back to the code in a year or more, you won't think "Who made this mess?" You will be able to find things and change them without too much risk of breakage.**
A good way to get started is to find various example programs and work through them. Then you can adapt them to your needs.
** One of my biggest headaches is trying to work with code written by people who did not think formatting or naming mattered.