acm-header
Sign In

Communications of the ACM

News

Python For Beginners


Python logo

Credit: Python Software Foundation

The way Taylor Poulo sees it, learning to code in Python is comparable "to learning Latin and romantic languages." Once someone grasps the logic behind Python, the concepts can be more easily transferred to other languages, maintains Poulos, a senior majoring in industrial engineering at the Georgia Institute of Technology (Georgia Tech). "Once you get comfortable thinking in a different type of logic and using different words, it's much more comfortable to learn new things," she says, adding that she was required to take three computer science classes at Georgia Tech, all in Python. "Python did that."

Python, an open source scripting language, has become the most popular introductory teaching language at top U.S. universities—Georgia Tech among them—according to a recent survey by Philip Guo, an assistant professor of computer science at the University of Rochester. Guo decided to conduct the research after noticing anecdotally over the past few years that Python was replacing languages such as Java as the de facto introduction to programming class in more and more computer science classes at universities around the country.

Because it is a scripting language, Python automates tasks that would otherwise need to be performed manually. Java and C++ also are popular and widely used. The main difference is that Python programs tend to run slower than Java programs, but they take significantly less time to develop, according to the Python Software Foundation. Python programs also tend to be shorter than equivalent programs written in Java because of "Python's built-in high-level data types and its dynamic typing," the Foundation notes. While the same is true of C++, Python code is generally one-fifth to one-tenth the length of equivalent C++ code, and "Anecdotal evidence suggests that one Python programmer can finish in two months what two C++ programmers can't complete in a year," the Foundation's website states.

During the summer of 2014, Guo went to the websites of the top 39 U.S. schools for computer science as ranked by U.S. News & World Report in 2014, and collected as much data as he could from looking at their introductory computer science courses. He stopped at 39, he explains, because there was an eight-way tie for 40 and "we had to stop somewhere." At schools including the Massachusetts Institute of Technology (MIT), Carnegie Mellon University, and the University of California, Berkeley, Python emerged as the leading language to teach novices (the full list, along with Guo's blog on the topic, can be found at at http://bit.ly/W0vtox).

Proponents say it is no surprise Python has become the most popular teaching language in colleges, because compared to programs like Java, it is easier to learn and to use to write programs that do practical things with very little code.

With Python, "There's very little overhead in getting to the point where people can start to write interesting programs; the syntax is pretty straightforward," observes John Guttag, professor of electrical engineering and computer science at MIT, and the author of several books, including one about learning to program in Python. In contrast to Java, which has a "fairly complicated syntax and fairly complicated static semantics," Python makes more sense for people who are writing small programs, he says. Java is designed to support people writing large, "industrial-quality" programs containing thousands of lines of code, says Guttag, who teaches one of two introductory courses offered by his department.


In contrast to Java, Python makes more sense for people who are writing small programs.


Another reason Guttag believes more colleges are using Python as an introductory programming language is that it has "a very large set of highly useful libraries that have been built over the years that support things ... that are easy to use from language proper, and that makes Python a particularly useful language for scientists and engineers who want to take advantage of those libraries."

Python is also very good for "letting you teach conceptual material without getting in the way," observes Guttag. "So I don't find myself spending all my time explaining Python to the students. I get to spend a lot of time explaining what I think are more long-lived concepts," like algorithmic complexity.

Not everyone agrees Python is the be-all-end-all as an introductory programming language. Shriram Krishnamurthi, a professor of computer science at Brown University, acknowledges Python has many nice features. "It offers a pleasant syntax, a large set of libraries, and an interaction loop ... all of which are very useful for teaching. Compared to the noise and complexity of Java, it is indeed a very nice step forward." He agrees Python has made people feel more comfortable about exposing programming to a much broader audience of students.

"There are many students I would not dream of teaching Java to that I would happily show Python." That said, however, it does not take long to discover Python's weaknesses, Krishnamurthi notes. Among them are that "Creating non-trivial data structures is onerous, because Python does not provide straightforward means for creating new structured data. You have to understand a bunch of unrelated concepts, like classes, and their onerous syntax and tricky semantics, which greatly reduces the benefit of simplicity that Python was supposed to offer."

Because of this, he believes more and more curricula are ditching the idea of structured data—one of the central concepts in computer science—and doing one of two things: shaping their curriculum to avoid them, or pushing students to encode more-structured data in less-structured formats provided by default in Python.

"This lack of data structuring and classification has a significant negative impact on teaching program design," Krishnamurthi says. "The best program design methods we have right now focus on data-driven design, which derive from the structure of data."


"Choosing Python is the modern equivalent of the old adage, 'nobody ever got fired for buying IBM.'"


Additionally, Python has limited support for testing, he says. Even though it has professional testing libraries, he says they can be "onerous for beginning students; the language provides no native support for it, which makes the user interface of testing significantly weaker than it should be." Testing is not just a matter of finding bugs, he adds. "It also guides students towards the design of solutions and greatly affects how one views debugging. Thus, another vital design and development methodology is taken away."

Lastly, Python lacks static types, says Krishnamurthi, which "is a central point in teaching programming, and should not be put off for too long. Python offers no good means for teaching this."

Guo says he got some backlash from older colleagues who do not view Python as a serious programming language, along with comments that it is not as "industrial strength" as other languages. One comment he received after posting his blog on the topic is that Python is a dynamically typed language and "There's fair amount of instructors who prefer statically typed languages, like Java," Guo says. "So they aren't as happy about this new movement."

Mark Guzdial, a professor in the School of Interactive Computing at Georgia Tech, says Guo's research notwithstanding, Java is still the most popular introductory programing language in the U.S. Guo "constrained his search to top U.S. universities," Guzdial says, "and in general, if you look at book sales, Java is still the most common [language taught] and C++ is second."

Yet, Guzdial agrees that if someone lacks any prior programming experience, Python is a good language with which to start. "There's a significant amount of evidence that graphical programming languages are easier for people to get started with than textual," he says. "If you understand variables in Scratch, it'll be easier to understand variables or conditionals or loops in Python."

Like Krishnamurthi, Guzdial thinks Python may broaden the scope of people being able to code. "It is easier and more accessible and ... you can get more done in fewer lines of code."

Matt Guthmiller, a sophomore majoring in electrical engineering and computer science at MIT, says he was not terribly surprised by Guo's finding. Guthmiller took his first Python class as a freshman at MIT, but he already knew how to code in C, C++, and JavaScript. "It definitely seems to make a lot of sense as an introductory tool because it's easy to learn, with lots of functionality built in, and you can do things that in other languages you'd have to build yourself, and [in Python] they're provided for you."

He likes that Python allows you summarize a list of data in one line of code, whereas in other languages it would take multiple lines. "You have to think about the order you want to iterate these items and implement them, so there's a lot more functionality built into one line, so if there's a problem you want to solve in one line of code, you get much closer to solving the problem than in other languages."

Like Guttag, Guthmiller feels the biggest disadvantage of Python is that "the syntax is quite different from most other programming languages," making it trickier to move on to another language once you get all the general concepts down. However, he says, Python's advantages outweigh its disadvantages.

Guthmiller recently used Python to build a controller for a robot to make it follow along a wall, although, generally speaking, his go-to programming language is C++. Python, he says, "gives you a lot of flexibility, and I'm very familiar with it and I am not concerned about having to remember small details."

Abbie Burton, a senior majoring in business at Georgia Tech, was required to take a computer science class and took "Jython," a combination of Java and Python that business students tend to take. She says most engineering students take Python or MATLAB, and she is not surprised by Python's popularity, "I guess because in the real world that's what people use, so they want us to be prepared."

There does appear to be a preference for using Python outside of academia. For the third year in a row, Python was ranked the number one most popular programming language by Codeval, a community of over 24,000 competitive developers, followed by Java, C++, and JavaScript. (http://bit.ly/1vLiuFj).

Guo says he has heard some comments that while easy to learn, Python does not have practical applications in the real world and that most coding is done in MATLAB and other languages. He says it all depends on the domain. "MATLAB is used in a lot of scientific domains. I definitely think it's less practical in terms of getting an industry job, because most industry coding would be in other languages, like Java or JavaScript. So I would agree it might not be the language you'd use in your job."

Guttag says Python is a useful tool for people who do not intend to be computer scientists, because it provides a good foundation for learning how to use computation as part of their work.

"For those non-computer science students," he says, "Python is an excellent choice as the introductory programming language."

Krishnamurthi says Python may be fashionable right now, but he believes it lacks staying power. "Computer science programming education goes in waves of fashion," he says. "Ever since Pascal introduced the idea of 'one programming language for introductory programming education,' the community has been stuck in a rut of trying to find one and then arguing about it. Pascal, C++, Java, Python, Scratch ... take a number."

He likens Python to a "package tour: safe, comfortable, blandly conventional. Choosing Python is the modern equivalent of the old adage, 'nobody ever got fired for buying IBM.'"

Guzdial is also not sure how long Python will be used as the main introductory programming language in academia. "I think Python has hit its tipping point, which may mean we have a couple more years before people say 'Python, what?'"

Back to Top

Further Reading

Guo, Philip J.
Online Python Tutor: Embeddable Web-Based Program Visualization for CS Education, Google, Inc. http://bit.ly/1zB7ugb

Guttag, J.V.
Introduction to Computation and Programming in Python, MIT Press (2013)

Guzdial, Mark
Exploring hypotheses about media computation. Proceedings of the ninth international ACM conference on international computing education research http://bit.ly/13SWMod

Enbody, R.J., Punch, W.F., and McCullen, M.
Python CS1 as preparation for C++ CS2. Proceedings of the 40th ACM technical symposium on Computer Science Education http://bit.ly/1tJjLu7

Pritchard, D. and Vasiga, T.
CS Circles: An In-Browser Python Course for Beginners. Proceedings of the ACM technical symposium on Computer Science Education http://bit.ly/1z7h8UV

How to Think Like a Computer Scientist. Learning with Python: Interactive Edition 2.0 http://bit.ly/1tJkknG

Back to Top

Author

Esther Shein is a freelance technology and business writer based in the Boston area.

Back to Top

Figures

UF1Figure. Number of top 39 U.S. computer science departments that use each language to teach introductory courses

Back to top


©2015 ACM  0001-0782/15/03

Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and full citation on the first page. Copyright for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or fee. Request permission to publish from [email protected] or fax (212) 869-0481.

The Digital Library is published by the Association for Computing Machinery. Copyright © 2015 ACM, Inc.

The full text of this article is premium content


Comments


Rodrigo Dias Arruda Senra

Dear community,

I would like to respectfully disagree with the following statements:

* "Additionally, Python has limited support for testing, he says."
* " ...onerous for beginning students"

Python has extensive support for testing, just check: unittest, py.test, nodetest, lettuce, splinter and mock to name just a few.

Moreover, it has native language mechanisms that allow dynamic introspection and injection (mocking and patching) that are vital to create flexible and unencumbered testing frameworks.

Another issue is the ease integration between Python and C, that allows teachers to ask their students to create libraries implemented in C (for studies about data structures for example) and automatically test them in Python. I did that as early as 2003, and spoke about it during Europython 2005.

best regards,
Rodrigo Senra
rodrigo.senra.nom.br


Marc Auslander

I was curious about Krishnamurthi's thoughs on structure. I was initially frustrated by python taking me back to my fortran days when comments documented the meaning of columns of an array!

But after playing with the namedtuple and (not built in) namedlist modules, I'm quite a bit happier. I have structs back - but structs which are wonderfully polymorphic, iterable, and quite natural.

I suspect Krushnamurthi is thinking of something richer than this - and I'd love to hear his comments or a pointer to an elucidation of his criticism.


Devon McCormick

The article mentions how "...Python allows you summarize a list of data in one line of code" and how useful this is.

I'm glad to see that at least a few people are starting to understand what we've been saying in the array-programming community for decades.


Shriram Krishnamurthi

@RodrigoSenra: I'm certainly aware of the testing infrastructure. However, library support for testing is never quite as simple and clean as having it integrated into the language, and the more friction there is the more barriers you erect to adoption. Many introductory courses do not talk about testing at all, or talk about it poorly. In particular, most people completely miss the difference between _testing_ and _examples_, the latter being used to drive the design of the program inductively. Nobody would write examples without good language support to make it as lightweight as possible, and indeed few do.

If you haven't, please look at how the student languages in Racket (e.g., http://docs.racket-lang.org/htdp-langs/beginner.html?q=check-expect#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._check-expect%29%29), or Pyret (http://www.pyret.org/), integrate testing and examples into the language. There is enormous pedagogic experience of the effectiveness of this. We even have studies of how well this works for peer-review (e.g., http://cs.brown.edu/~sk/Publications/Papers/Published/pkf-ifpr-tests-tf-prog/).


Shriram Krishnamurthi

@MarcAuslander: there's a difference between using built-in datatypesof which there is indeed a rich collectionand learning how to create your own. You may indeed be settling too easily! Do you also have built-in trees? Which kind: binary trees? N-ary trees? Balanced binary trees? Family trees? If so, ascending family trees or descending family trees or both?

Of course you could find libraries that implement these, but a programming course should also teach students to build their own. Also, if you follow a data-driven program design methodology (as in http://htdp.org/), you will find built-in structs quite insufficient because they do not give you rich, structural information about their components. That's why using built-in datatypes gets you only so far. However, because most introductory programming curricula have no clear design methodology, they don't notice this absence.


Allen Downey

We are proud that you recommended our book, How to Think Like a Computer Scientist as further reading on Python for Beginners. But we are disappointed that you did not acknowledge us as authors. The original version of this book was written by Allen Downey, Jeff Elkner, and Chris Meyers, and published by Green Tea Press (greenteapress.com) under the GNU Free Documentation License. This license allows anyone to copy and distribute the book, and to make modified versions.

The online interactive version of the book was converted and substantially revised by Brad Miller and David Ranum and is published under the same license. Since the interactive edition was published many people from around the world have made contributions and suggested changes on github.com/bnmnetp/runestone.

Free textbooks are popular and valuable resources, and they encourage and make possible successful collaborations like ours. But one of the barriers that discourages authors from working on free textbooks is the worry that their work will be appropriated and used without acknowledgement. We are sure the Communications of the ACM did not intend to compound this worry by presuming that online resources are authorless, unprotected works.


Esther Shein

Thank you for expressing your concerns, Allen. It was not our intention to slight any of the authors, whose names are clearly referenced when one clicks on the link to the interactive book listed under further reading material. We also made no suggestion, nor did we imply that the group's work should be appropriated and used without proper acknowledgment.


James Heliotis

In response to Dr. Krishnamurthi's quote about problems with Python and data structure, we agree with that sentiment. Last year we tried a solution whereby a superclass would create all the "standard" methods one might need. The student need only write a "class" header line and then the names of slots. What s/he gets for "free" is a constructor, equality tester, hash function, and string rep. function. (Some of these have limitations to non-cyclic structures.) We even added optional type "declarations" in the slot spec. This is because as our students get to the end of time that they're using Python, the lack of type checking gets to be a significant problem in rapid software development. If you're interested, please feel free to contact me. -James Heliotis, RIT.edu


Displaying all 8 comments

Sign In for Full Access
» Forgot Password? » Create an ACM Web Account