Why should you learn to program? In my (limited) experience in the world of marine science, fisheries, and ecology, programming is more and more becoming part of the expected tool set. Consequently, many grad students in these fields are struggling up the learning curve.
There are a lot of good reasons to learn to program. Many are mentioned in this recent Twitter conversation, prompted by a question from Dan McGlinn: how to justify teaching biology undergraduates R or Python instead of Excel? Most of the responses to this question focused on the ways R (or Python) is a faster and more powerful tool than Excel. Which is absolutely true: programming tools are far more flexible, powerful, and reproducible than spreadsheets. It has been seven years since I first learned to program, and it has been seven years since I last tried to use Excel for any data analysis. But with some perspective on it now, I think the best thing programming has done for me is the confidence it has given me to play with mathematics.
In school I was pretty good at math, but it was never totally easy for me (my anxiety dreams, to this day, are all about being unprepared for 11th grade pre-calc). This began to change, imperceptibly at first, when I started grad school. I was thinking about mathematical and statistical concepts all the time, by necessity. I was also figuring out how to analyze a large dataset using Python and R. I can remember one night when I was struggling to understand the Fourier transform, a fundamental operation in signal processing and time series analysis. The math on Wikipedia seemed hopelessly abstruse, and after a while I got frustrated enough to try writing it myself in Python. I was shocked–it worked! Everything was awesome!
The peanut butter of math had mixed with the chocolate of programming: two great tastes that taste great together. Math, in written equation form, can be abstract and intimidating in the extreme. Programming, on the other hand, especially in an interpreted language like R or Python, is very concrete and interactive. You can run commands one by one and get immediate feedback, then link them together into a larger program.
The beauty is that pretty much any mathematical concept can be translated into a computer program, which immediately makes it much more concrete. Vectors? They’re just lists of numbers! Multidimensional integrals? Just summing up the elements of an array! Complicated summations? Just write a for-loop! How does a function respond to different parameters? Just adjust some variables and plot it up!
For me, being able to do all this is like having an infinite set of mathemagical Legos. Programming lets me play with math in a way I just can’t do with pen and paper–and it’s a ton of fun! This is, in my opinion, a major dividend of learning to program that isn’t emphasized enough (or at all) to ecologists and natural scientists who are just starting out. It should be.