Fall 2006»Python


Python vs. Java in Intro to CS Courses

Note: Here are some quick ideas, organized haphazardly, to provide content for a departmental discussion. (Later note: Using these and other ideas, our department decided to switch to Python for CS1 in Fall 2007.)


In "Why Python?" Eric S. Raymond notes that:

Python ... is compact--you can hold its entire feature set (and at least a concept index of its libraries) in your head.

In "Why I Love Python" Bruce Eckel notes that Java is not compact.

I can remember many Python idioms because they're simpler. That's one more reason I program faster [in Python]. I still have to look up how to open a file every time I do it in Java. In fact, most things in Java require me to look something up.

The ACM Java Task Force Tutorial

The recent release of version 1.0 of the Java Task Force materials designed to support teaching Java at the introductory level.

This is the authoritative 90-page tutorial for prospective adopters of Java in CS1. It took 2 years to put together by a group of creative, intelligent SIGCSE folks.

Consider how much effort it takes to explain the code samples to students with no previous programming experience (our CS1 target audience).


Python transparencies

Here are Zelle's Python transparencies.

Consider how much effort it takes to explain the code samples to students with no previous programming experience (our CS1 target audience).


(Yes, Python reads like Java pseudocode. And, if you know Java, you already know Python.)

If you have a minute, download and install Python IDLE (http://www.python.org/download/)

Here is a quick tutorial for programmers (and one for non-programmers).

Python & Java: a Side-by-Side Comparison

"A programmer can be significantly more productive in Python than in Java. How much more productive? The most widely accepted estimate is 5-10 times. ... Of course, programming languages are tools, and different tools are appropriate for different jobs."

"Both Java and Python are strongly typed languages [- no mixing of apples and oranges]. However Java is statically typed, whereas Python is dynamically typed."


Strong versus Weak Typing

"Languages like Java and C++ place much focus on [static] strong typing, as if once your program is type correct [at compile time], it has no bugs left. ... And all of that goes out the door the moment you say, 'Well, we're just going to write a container of Objects, and you'll have to cast them back to whatever type they really are once you start using them.' That means you have even more finger typing, because of all those casts. And you don't have the helpful support of the [static] type system while you're inside your container implementation."


Strong Typing vs. Strong Testing

"It takes an earth-shaking experience - like learning a different kind of language - to cause a re-evaluation of beliefs."

"After I had worked with Python for awhile - a language which can build large, complex systems - I began noticing that despite an apparent carelessness about type checking, Python programs seemed to work quite well without much effort, and without the kinds of problems you would expect from a language that doesn't have the strong, static type checking that we've all come to 'know' is the only correct way of solving the programming problem.

This became a puzzle to me: if strong static type checking is so important, why are people able to build big, complex Python programs (with much shorter time and effort than the strong static counterparts) without the disaster that I was so sure would ensue?"


Typing: Strong vs. Weak, Static vs. Dynamic

'''Similarly to Java, Python is strongly typed. The confusion is that Java attempts to do *static* strong typing, whereas Python does *dynamic* strong typing (or latent typing). '''

Python's conceptual model is simpler: all type checks are done at runtime. Simpler does not necessarily mean simplistic. (Like our Macs.)

Java's conceptual model is inconsistent: some type checks are done at compile time, and others at runtime (resulting in runtime exceptions).

C/C++ are weakly typed relative to Python.


Interesting Correlation

There are various hypotheses about dropping enrollments in CS (dot-com bust, outsourcing, etc.)... and for the around-the-corner increasing enrollments (e.g., Google's acquisition of YouTube).

None is supported by any quantitative data.

Here is an interesting observation: Look at when Java became popular as a first language.


How does this compare with when we started loosing students?


There is a correlation. But what about a causal relationship? Hard to tell... Here are some supporting thoughts:

Java is an industrial strength language. It's hard to master (even for faculty). CS intro books have gotten thicker (not with concepts, but mainly with syntax). Certainly our own experience here at CofC is that we started losing students from other departments when we moved to Java (and OO).

A similar argument can be made for Unix. How many departments use it as the platform of choice for CS1? Why not?

Of course, the world is too complex to believe that dropping enrollments can be attributed to a single factor.