Why Not Learn Python?
Perhaps a better title for this article might have been “Why Learn Python?” but I think that more people might respond to the challenge as presented. It implies that learning Python might not be so difficult and that doing so may be worthwhile, which is certainly the case.
Like many practicing programmers, I have worked productively with many programming languages and environments. Since I have been actively teaching, doing research, and developing software since the late 1960s, I probably have used many more programming languages than most. But I have to admit that I was dragged kicking and screaming into each one. Well, assembly language was definitely better than machine language, but beyond that, every new environment has seemed to present just as many challenges as advantages, particularly when one is trying to get a job done.
So, why Python? We tell students that there are many reasons to learn a new language:
- It offers something new, perhaps a new style of programming
- Your job requires it (the ability to learn new languages is a skill you need)
- It is well-suited for the application at hand
- It provides an intellectual challenge
- It is an opportunity to learn something about computation
Sure, there are plenty of things that I dislike about Python. As Bjarne Stroustrup put it so aptly: "There are only two kinds of languages: the ones people [complain] about and the ones nobody uses.” I don’t like Python’s cavalier attitude towards encapsulation, typing and performance; its naming and indentation conventions; the major backward compatibility issues; and a hundred other things. Of course, I have similar lists about other languages I use and have used.
But we all have to realize that there are a great many people out there who do not care about such issues. Python enables people to write elegant programs that are easy to understand, and it provides powerful and extensive libraries that are easy to use. There are a lot of people who would otherwise not be programming who are productively using Python. That’s what I like most about it.
Our new book An Introduction to Programming in Python: An Interdisciplinary Approach, (Sedgewick, Wayne, and Dondero, Pearson, 2015) is intended to be a resource for anyone to learn Python. It is a textbook, but of course experienced programmers can skim through the early material. Engaging with the material in our book is an efficient way to learn the language. A professional programmer might be able to work an exercise in a few minutes that would take a student an hour to do, but both will learn something. We also have a large number of interesting sample programs, a website that contains extensive additional information, standard libraries for I/O (including graphics and sound), and an interesting narrative that you can skim or study to help put Python programming into perspective.
Every new language seems to come with messianic practitioners who defend every design decision to the death and rail against anyone who might have a different point of view. And nowadays, such debates spill onto the web, with much more heat than light, ignoring serious issues that have been addressed by serious researchers for decades. Python is no exception. My advice is to ignore all such dialog until after having written several programs that do something useful.
As I said, I was dragged kicking and screaming into Python programming, but I find myself using it much more often than I ever thought I would. And I’ll probably continue doing so, at least until I’m dragged into learning the next great language that comes along.
Everyone should learn to program. Once you learn Python, if you have the time, you can teach it to your boyfriend, your girlfriend, your parents, your husband, your wife, your kids or your grandkids. Why not?
Robert Sedgewick
Princeton University