Ten-Minute Talks: Learning Python
- Joe
- Feb 4, 2019
- 4 min read
Depending on who you ask, the most useful office skill you can have right now is programming. As I’ve gotten more comfortable with programming, I’ve talked about it more, so it was only a matter of time before I got the question I’d been asking a couple of years ago: how do you learn to code?
Beginning in my sophomore year (of college), I knew I wanted to learn to code. I’d heard of Python, and I’d heard how valuable it was as a skill. Whenever I asked others how I could learn to program, I got the same answer: just try to program something!
But that was way beyond my level. I didn’t know what was even possible with programming, let alone where to start on them. So I found some free online courses to try to teach myself.
The first thing I learned was how to take a word and spell it backwards. After a couple lessons, I was still just unscrambling words, doing useless tasks that made no sense to me. So I stopped. At the time, it was because I felt I wasn’t learning anything useful.
But thinking now, I think it was just too slow. Learning a few particular Python functions wasn’t helpful because I still didn’t understand the point of programming. There was no motivating picture; I didn’t know what I’d be able to do by programming.
In my second semester of sophomore year, I took a class centered around Matlab. We spent a few weeks at the beginning of the class learning about your usual programming tools: loops, lists, variable types, and functions. The rest of the class was focused on applying those basic tools to apply numerical methods. The assignments provided the math, and we had to program it. This is the point when I realized I enjoyed programming. It was like learning a new field, with new tools, methods, and vocabulary. More importantly, I started to think in a new way, recognizing my computer’s ability to do simple, repetitive tasks very quickly.
Here’s an example. At some point, we were tasked with writing a program to take two integer values from user input, sum all of the integers between them, and display the result.
There’s a formula for this based on the series math that somebody has already derived. But if you didn’t know there was a formula, how would you do it? You’d manually add every number in between the given bounds until you got your final answer. This straightforward, tedious process is actually pretty easy in a script. You create a loop that begins at the low integer and ends at the high integer, counting up each time and adding the new number to a sum. Unless the user is a jerk and chooses some really large numbers, this crude program can execute pseudo-instantaneously.
This numerical methods class kept giving problems to solve with programming. When trying to solve them, I got better at understanding how Matlab could store data and manipulate it. I understood the process of indexing. And the process of solving problems using these newfound tools was enjoyable as long as I had interesting problems to solve.
The next semester, I took this new mindset and skillset with these basic tools and started using Python. In a introductory Operations Research class, we began to use Gurobi to solve large linear and integer programs. With some understanding of the principles of programming (and plenty of example code from the instructor), I was able to piece together the logic of each program. As I used more packages and had more questions, I got better at searching for help online. The language that once seemed so useless to me was now a powerful tool to solve interesting problems. Since then, I’ve taken every opportunity to use Python for coursework. Whether it’s solving large probability problems or using numeric integration to check my handwork, python became a regular tool I used. All of that led to my experience with it last semester, with our self-driving shopping cart Hextor, and my latest project creating a data-driven March Madness bracket.
Each of these opportunities gave me a motivation to learn something new. But I wasn’t learning something as broad as “Python.” I was learning specific things, like taking numerical derivatives in SciPy or using the csv package to store information in a dictionary, or finding the maximum value in a particular column of a Pandas data frame.
I still came across projects that were far out of my comfort zone. I know next to nothing about machine learning and the scikit-learn library, or image processing in OpenCV. So to apply these, I started with tutorials. By pulling other code from GitHub or finding tutorials online, I started by looking at another (more experienced) programmer’s entire method, doing my best to understand the pieces of the script, and adjusting things here and there to meet my needs. Seeing some basic use of a package or technique in a tutorial showed me the specific things I could search for to learn new methods. In the process of running code, running into problems, and Googling my way to solutions, I developed a pretty good understanding of the tutorials I was borrowing from.
Don’t get me wrong: self learning is difficult. I had to learn the fundamentals of programming in a class, not on my own. But after that, my learning process became very unstructured. I think this is what makes programming so frustrating for people. There’s not a linear way to learn to program. You have to find something new to try, realize it’s not working, figure out why it’s not working, then repeat. All of this has to be housed within a project you find worthwhile, or there’s no reason to continue with it.
I really hope this post has given a bit more detail than the classic “just try to code something” approach to learning to program. When I first began, I remember that phrase constantly frustrating me. It felt like a cop out and a non answer. If you’re looking for a place to start, I’ve seen some promise in Automate the Boring Stuff [[http://automatetheboringstuff.com/]] for learning the basics (like functions, loops, and conditional statements).
While I certainly don’t think I have enough experience to call myself a “programmer,” I enjoy using it as a tool for school and for hobbies. There are few things that compare to the satisfaction of seeing a piece of code execute properly. Hopefully this post gives a helpful perspective for people who are looking to learn how to use programming to solve problems.
Comentarios