Teach yourself to code

5 minute read

Published:

As most lab work at the University of Michigan comes to a temporary halt due to the ongoing COVID-19 pandemic, we’ve heard some of our fellow grad students and other researchers express an interest in learning how to code as they’re not able to conduct experimental work at this time. We thought we could help out by putting together this short guide on how to teach yourself to code.

First above all, take care of yourself and your loved ones! We don’t want to contribute to the voices pressuring academics to be productive at a time when we should all be prioritizing our mental and physical health and that of our families. If you also have found the motivation and time to teach yourself how to code, then this guide is for you.

We wrote this guide with grad students, postdocs, and other scientists who have never written code before in mind, but most of the content applies to just about anyone wanting to learn.

📣 UPDATE 25 Mar. 2020: Pat Schloss is running a weekly Code Club via Zoom for those who want to learn R and improve their data analysis skills. All experience levels are welcome! See details here: riffomonas.org/code_club.

Why learn to code?

What language to learn?

If there’s a single popular language that everyone else in your lab, department, or field uses, just start with that one. Why? You will want to be able to learn from others and ask for help when you need it. For scientific research, both R and Python are popular languages and great for getting started quickly with data analysis. R and Python are open source, meaning they are free as in libre and free as in free food at the department seminar! So you don’t need to buy a license to use them, you’ll have access after you leave the university, and anyone else with a computer will be able to run your code too.

Scientists in the DANG! community use R, Python, and/or other languages, but R seems to be the most common. If you’re not sure which one to pick and you’d like to get help from the DANG! community, try R. We also particularly like R for a package called R Markdown for turning code into analysis reports, manuscripts, and even presentations to easily & reproducibly share our work with others.

The logic of programming is the most important thing to learn, so deciding to pick up another language once you have experience in one should be easier. And it’s definitely not an “either/or” scenario; many experienced programmers use multiple languages regularly in their work. However, we recommend sticking to learning just one language at first so you don’t get overwhelmed.

How to get started?

  • Code Academy is a good place to start for their free beginner R and Python lessons in an interactive format. Note that the free version of the Python lessons teach Python 2 (not Python 3). You should definitely use Python 3 if you’re going to use Python in your work, but there are very few differences in how you code Python 2 and 3, so learning Python 2 is still very valuable because almost everything translates to using Python 3.
  • Zena and her sister Maya created a guide to teaching yourself R. It takes you through the Code Academy lesson and also has extra exercises to practice data analysis.
  • The Carpentries is an organization that holds workshops to teach introductory programming skills to researchers. U-M has a Carpentries chapter that holds workshops regularly throughout the year (with the exception of during pandemics 😬). We highly recommend attending an in-person workshop if you get the opportunity, but you can access the lesson materials for R and Python online if you’d like to learn on your own. The Carpentries has also translated their R lesson to Spanish.
  • As part of Girls Who Code at U-M, Zena and Kelly have contributed to a curriculum teaching Python for Data Science aimed at high school students. You can find instructions for getting started here.-
  • RStudio has interactive tutorials where you can learn everything from the basics to writing reports to building interactive web apps.

If you’ve exhausted these options, here’s an overwhelmingly long list of links to even more resources and tools you might like to learn.

How to use it in the real world?

If you want to automate tasks, run your code on supercomputers, and make your friends think you’re a hacker, you should definitely learn the Unix Shell. You can find The Carpentries’ lesson on the Unix Shell here.

The Carpentries has instructions for installing the tools you’ll need:

How to get help?

  1. Google is your best friend. No, really. We Google questions every day!
  2. Ask your friends, colleagues, etc. Especially when you’re just starting out, it can be difficult to know what to Google to get the answers you need. Ask a more advanced programmer as soon as you hit a wall.
  3. Join the DANG! Slack workspace and use the #analysis_questions channel. DANG! exists because we think it’s important to have a community of practice so you can learn from other people, get personalized help when you need it, and help others.

Further reading:



Written by Zena Lapp & Kelly Sovacool. Edited by Ari Kozik.