Ever since I started in Magnetic Resonance Spectroscopy I did a lot of programming in Matlab, C, C++, LabVIEW, html, and more recently Python. All of it is picked along the way, without ever having a class in programming. With that a lot of bad habits evolve over the years. No matter what programming language is your currently choice, take a look at this very nice article. If you don’t want to read through the whole thing take a look at Box 1 on page 2 to get an idea of the basics.
Wilson G, Aruliah DA, Brown CT, Chue Hong NP, Davis M, Guy RT, et al. (2014) Best Practices for Scientific Computing. PLoS Biol 12(1): e1001745. https://doi.org/10.1371/journal.pbio.1001745
Scientists spend an increasing amount of time building and using software. However, most scientists are never taught how to do this efficiently. As a result, many are unaware of tools and practices that would allow them to write more reliable and maintainable code with less effort. We describe a set of best practices for scientific software development that have solid foundations in research and experience, and that improve scientists’ productivity and the reliability of their software.