On learning to code

A few people have asked me for advice on learning to code, including questions like:

At the risk of generalizing my own experience to advice, I'm happy to point people to resources. I think it can look like people who program do so magically, calling upon some unbridled genius that is then channeled write import glob as glob or whatever. It's not magic, it just takes a certain thought process and lots of practice.

Which coding language would be most useful for me to learn?

Which coding langauge is right for you depends a lot on what your needs are. I usually recommend that people learn Python. It's free, there are great online resources, the syntax is human-readable, and there's plenty of room to do complex things with it later if you so choose.

That said, my first coding language was Stata. The huge upside for me was that it was developed by economists, and so the logic of the language made a lot of sense with how I had been trained. The other reason why it was a good intro language is that many of the tutorials focus on applied data analysis, which is something I care about. It has the downside of requiring an expensive license. If you really like data visualization, maybe look at JavaScript (particularly the D3 library). Even Excel can be programmed to do some pretty fancy things.

Do I need to take a class to learn to program?

Programming classes can help, but aren't necessary. For me, the best way to learn about programming is to solve a problem using code. Having a problem gives you something concrete to use as a learning tool, and forces you to stick with it if you are invested in solving the problem. After graduating from college, my first full-time job involved coding 100% of the time. One learns a lot about "how programming works" and the software engineering side of programming over the course of this. One learns about good coding practices for scientific computing and why reproducible work is awesome.

Staring at code on a projector wasn't useful for me, nor was it a good way to engage with the concepts. Furthermore, intro classes usually include people with varying experience with coding and algoritmic thinking. Even if someone has never coded before, it helps if they've been exposed to the concept of a loop; depending on the class atmosphere, this varying experience can discourage asking "stupid" questions. After coding for a while, you realize that the best debuggers are those self-aware enough to ask those questions, but many beginners don't want to appear clueless. And finally, classes usually involve an investment of money and/or time. It can be a good investment, but I also think that there are some key applied concepts, that once you have the basics and learn how to search for help, you are good to learn the language according to your schedule and needs.

That said, there is a lot of value in learning from other people. Once you get the basics, I think there's a lot of value in learning about new techniques in group settings. But people should use group settings in a way that benefits them, and if it isn't beneficial, don't take it as a sign that coding is not for you. It could just be that those particular people are not for you.

Do I need to have a background in Computer Science/Math/Statistics/Data Science/Name-your-scary-sounding-thing to learn how to code?

You definitely don’t need a background in Something-Terrifying to learn how to code. Plenty of programmers I know studied Art, Music, Sociology, Biology, etc. I think that coding can be very rewarding for people who think creatively and like to build things. The great thing about it is that there are applications in pretty much every field. Tedious things can be automated. This is wonderful - now your brain is free to work on things that are less tedious!

For me, having a background in econometrics was incredibly helpful. Seeing statistical concepts translated into code helped me have a deeper understanding both. Statistical programming has had many positive impacts on my work, incuding implementing analyses more efficiently, processing large datasets, and learning new statistical techniques. But perhaps the most salient is how it validates my quantiative abiities, but also my creativity and empirical observations, independently from other people. Coding is for anyone who codes, which is the beautiful thing about it.

Tutorials

If you are looking for tutorials, I'd suggest the following:

Python:

Stata:

Git:

R:

Javascript (D3):