When in doubt, write a description
/One of the most common causes of programming problems is not knowing exactly what the program needs to do before you start writing the code. You have a vague idea of how it is supposed to work and so you start knocking out statements, thinking you can fill in the detail later.
This is a really bad idea. It doubles the length of time it takes you do do anything, because half way through writing the code you’ll discover that your understanding of the problem is faulty, and you have to either fiddle with what you’ve built, or start again from scratch.
A much better idea is to try to write down a chunk of text which describes what you think the program or module should do. You don’t need to go down to the level of individual statements, just a general idea of what the ins and outs are supposed to be. The act of doing this will force you to think a lot harder about what you are trying to do, and hopefully mean that you will make fewer mistakes when you go to code. I find this useful even (or perhaps especially) because I’ve done a fair amount of coding. The stuff that I write ends up in my diary so that I can refer back to how my code works (which is also super useful).