I’m primarily a self-taught programmer. I have taken a handful of classes, which is precisely why I’m pro teach yourself. Having a vision for what you want to create with code makes everything so much easier.
So, you have some idea about what you want to program. Start by writing pseudo-code. This is the logical sequence of how you want your program to run. What feeds into what, what functions or sub-functions do you need, what are your outputs, inputs, variables? Do you need some kind of loop? Pseudo code can be very vague, as an outline of what you want to accomplish, or more specific, if you know for a fact you’ve got to do some tedious wrangling. Use it as a sort of programming to-do list, to keep your thoughts straight. It’s pretty easy to go down rabbit holes of how to do something ultimately minor. For example, I spent 2 hours last night figuring out how to make R Shiny have a footer with the time I updated the site and my name. Was the furthest from necessary, but I think it’s pretty cool… Luckily I had my list of features to fall back on after I recovered.
Google whatever it is you’re trying to do, plus whatever language you’re trying to do it in. You’ll find something related. Copy and paste that into your console, and run it. Then, you can set breakpoints and take notes via the comment function to figure out what each line or command is doing.
Eventually you’ll come up against an error. READ THE ERROR MESSAGE. This part is the hardest thing to learn about coding. Most error messages you’ll come across in scientific coding are actually useful and tell you a ton of stuff. What if you don’t understand the error message? Copy, paste, Google it. Most likely someone’s had a similar issue.
This process may take a few iterations – search for what you want to do, paste it in; search the meaning of the error message, then fix that; move on to the next feature. Coding is an exercise in patience, and it can be extremely tedious. But once you learn how to do something, you can re-use your code! Particularly if you are very good at commenting your code. This is the second hardest thing to learn, but its OK. You have to be patient with yourself too.