Skip to content

How do I learn to program

michaelmarty edited this page Jul 11, 2022 · 3 revisions

How do I learn to program?

One question I get asked sometimes, by my own students and others, is how to learn programming. There are two primary challenges to getting started. First, you need to know the language. This tends to be relative easy with a few tutorials. Second, you need to learn how to think programmatically. This tends to be much harder. The best way to learn both is to start with a problem or goal and then work on solving it.

Ideally, start with some example data or a simple test system where you can track as you go if it's working. Use plenty of plot and print commands to see what is happening. Don't be afraid to try something and make mistakes. It's rare that you do something that would actually crash the computer, and even then a hard reset will always fix it. I don't know of anyone who actually permanently broken a computer through some mistake programming. In other words, just dive in and try things.

Here's a rough guide that I'll try to keep working on for suggestions on where to start and what to do.

  1. First, do a simple Python tutorial online to learn the language. Don't spend too much time on it. You just need to learn some of the basics about syntax and key functions to use. Don't pay for anything; save your money. If you can find it, look for tutorials that include numpy, matplotlib, and probably pandas. This is a pretty good one https://www.learnpython.org/.

  2. Once you have the basic syntax down (maybe before if your tutorial is not online and requires this), set up your computer for programming. Download and install Python. I highly recommend PyCharm as an Integrated Development Environment (IDE). An IDE is a program specifically designed to help you program and test code. It is a huge benefit to have at all stages.

  3. Once you have the environment set up, create a new Python file. Write <print("Hello World"> and run it. You are now officially a programmer. Congrats! Now, try experimenting with some basic math functions. Import numpy and play around with making and doing math on arrays of data. Look up tutorials online where you need. Google is your friend here.

  4. Now, write a simple script to import your data from a text or csv file and print it. The goal is to get data from your hard drive into a format you can use for programming.

  5. Import matplotlib and learn to plot the data you have. Play around with color, markers, and line style. Add text and dots and vertical/horizontal lines to your plot. Resize it and change the axes labels. Again, look up or ask for help with how to do these. It might be helpful to take a few notes about the key functions and options you are learning.

  6. Now, try learning how to interact with the operating system and folders on your hard drive. Write a script to scan a folder and identify all the files that match a specified string. For example, have it search for all files ending in ".txt" in a given folder. Next, learn how to use for loops to cycle through all these files and add them to your plot. Or, make separate plots from each. The goal is to be able to automatically import and plot several pieces of data.

  7. Try parsing the file names to extract key information. For example, if you included something like "_20C" to indicate that this data was collected at 20 degrees Celsius, extract that and convert it to a number that you could use.

  8. Now that you can extract information from your file names, try extracting information from your data. Try chopping it down to a narrow range. Take the mean or the sum of the data. See if you can plot that.

  9. Keep going with whatever problems you want to solve. Honestly, if you've made it this far, you've got an awesome base of knowledge to build from, and you will be set :)

I'll keep working on this as inspiration strikes. Please let me know what suggestions you have. I would love to have contributions here to help refine this. Thanks!!