I'm not a programmer, but I've dabbled with a lot of languages now just to get the job done.
I normally start off with a clean slate or something that works and just change a bit at a time and re-run it, to ensure that I've not got the syntax wrong.
Its not the most efficient way to do it, given you'll find that the code changes from what you first start out with to what you end up with and it takes a lot of trial and error.
However, if you know roughly where you are having problems just post that section.
I had a funny one yesterday that was throwing errors.... and it was really giving me a headache.... then I noticed that there were a few commas missing...... it ran a little better, but still would not run and threw up a load of other errors.... I then found a pesky semi-colon missing !!!!
its a problem when you flit from C to C# to python etc etc! And you have a day job that is not cnc / programming related. And you don't get endless time to just work on one thing so you flit in and out of it in 10 or 15 minute sessions and have to regather your thoughts and what you tried last time or were trying to do.
mind maps / flow charts can help, I keep a load of note pads and just scribble whatever in them so I can just rescribble / add to the flow charts of whatever I'm trying to do and I can also flip though and see what did not work.
Key to programming is just finding what works for you, most people are self taught anyway by necessity