As many of you know, computer programming has sometimes been the bane of my existence. Since coding is necessary to make any significant contributions to modern mathematics, I have learned to somewhat get along with it. I studied FORTRAN as an undergrad, at first simply as a program requirement, but I learned it well enough to write a program that measures how close a polygon is to being convex, which was an important part of an undergrad research experience involving gerrymandering. As a grad student, I was forced to learn MATLAB, again first as part of a class. That class didn’t go so well, but I later got a grasp on MATLAB and found it to be quite useful. Yet when I took on some combinatorics research this summer, my professor suggested learning Sage, which is based in Python. I had heard that Python was the simplest and most intuitive of the computer languages, but given my struggles with coding, I wasn’t sure how this would go.
See, my main issue with programming is the very different ways in which my brain and the computer “brain” approach solving a math problem. I like to compare programming a computer to conversing with a two-year-old. The computer has absolutely no intuition. It must be told EVERYTHING. Things that the human mind takes for granted and doesn’t even consciously consider when solving a problem must be spelled out in painful detail for the computer. And then of course, there are the inevitable errors, often as frustratingly simple–and even more frustratingly hard to find–as a missed colon. Of course, the computer never says “you missed a colon in blah blah line”; it gives some cryptic error message. Think of this as the two-year-old having a temper tantrum.
So I got a book and found some websites and began my adventures in Python coding: loops, if-else statements, print commands, and other simple fare. And it was going well. Python did seem to be a much easier language to understand than FORTRAN or MATLAB. Still, I was cautious, waiting for the inevitable problems to arise. And sure enough they did as soon as I tried to make some of my programs interactive. Sage quickly freaked out with cryptic error messages as soon as it encountered my “input” command. I could not understand this, since I was copying code directly from my book. I asked the masses on Twitter for help and got some, but I still had issues. I consulted various websites and even asked one of my students who knows Python for advice. And yet, it was only through some fooling around and following my nose that I finally stumbled on the proper command (Sage prefers “raw_input” rather than “input”). And suddenly my program was interacting flawlessly. And the feeling of joy was indescribable.
Suddenly, coding didn’t seem so scary anymore. I realized in that one instance that, while errors were inescapable, they didn’t mean I was incapable of coding; after all, I had just figured out how to code something entirely on my own. And the fact that I was doing it all in the context of a project I was very excited about made it that much better. And finally, yesterday I also saw a preprint of a paper based on that research I did as an undergrad, and I was reminded that I have indeed successfully coded important programs in the past and that I can do it again. I guess all the code stars were aligned yesterday. Hopefully, things continue this way. With my new attitude, I feel that they will.