I recently read a tweet by a computer science educator claiming the superiority of a particular programming language for teaching purposes (Pascal, if you must know). Now, I don't really go for religious wars -- each to his own and all that -- but I did reply with my opinion that Python might generally be a better choice.
Of course, language choice depends on the audience and what you're trying to achieve. For very young students (younger than 11 or 12), I'd say a language like Logo is most suitable. Older programmers with experience might have particular requirements that Python can't fulfil; they might need to learn low-level stuff for example. But for a general introduction to programming, I think Python is ideal.
My suggestion of Python was dismissed by the original tweeter on the grounds that "Pascal is easier to learn" and we have "more experience of teaching Pascal." I dispute the first reason. And to be honest, I don't really know what that last reason actually means. Someone able to teach programming languages shouldn't take too long to learn and adapt to a new one; plus, those doing the teaching in universities are often teaching assistants or graduate students anyway who have probably no experience of Pascal on account of their youth.
Anyway, I thought I'd make clear my reasons for Python preference in a blog post -- after all, it's a bit more flexible than a 140-character tweet.
Python is famed for how it departs from the norm by assigning meaning to a program's layout. Instead of using curly brackets or keywords like
end, the code's structure is made clear by how it's indented. This has resulted in Python being given the nickname "readable pseudo-code". Pseudo-code is what we normally teach students to draft their programs in first, so it's a very short step between their draft version and the finished version of a program.
This is just one aspect of Python that gives it a clean overall appearance. Another is how Python disposes of numerous bits of syntax that other popular languages insist on: all those brackets and semicolons, which beginners find distracting.
When I first started programming, I was using machines like the Commodore 64 or the Sinclair Spectrum. Those who remember them will remember that switching the machine on launched you instantly into the BASIC programming environment. If you had even the slightest curiosity about programming, it wouldn't be long until you were typing in commands and trying to make your computer do all sorts of cute, fun little things. Remember this?
10 PRINT "FRANKIE SAY RELAX!" 20 GOTO 10
Programming on these old computers was so accessible because they were REPL (Read-Eval-Print Loop) environments. There was no infrastructure to set up, no compilation to worry about, and instant feedback about what you'd done. Programming like this can often be a revelation, because if you're one of those lucky people who "gets" what all the fuss over programming is about, seeing a program instantly do something can draw you in very quickly. It would be a shame if beginners were put off by "heavy" languages which demand lots of work before their work bears any fruit whatsoever.
Python gives you this same REPL environment as standard. All you have to do is launch the Python interpreter, and you can start instantly entering lines of code for instant feedback.
Wide use in FLOSS
Python is a popular language, but I'm not usually one to let popularity get in the way of making the right choice. However, this popularity does give programming students a distinct learning advantage: Python is widely used in free/open source software projects. (Check out the stats on places like Freshmeat or SourceForge, and you'll find thousands of projects coded in Python.) Why is this important? Programmers learn best by doing, not by listening to a lecturer or just reading a programming book. The next best thing to writing code from scratch yourself is to get hold of an existing program and go through the source, reading, learning, tweaking, extending. With thousands of FLOSS programs available covering every conceivable type of software, the student is spoiled for choice.
Python provides a few things out of the box which are instantly accessible to the beginner but not enforced. The first of these the student is likely to need are the built-in data types, specifically lists and dictionaries, and using them is as simple as
x = ['a', 'b', 'c']. Worrying about other data types (integers, strings, booleans and so on) can be delayed because of Python's dynamic typing, a helpful feature in itself.
There's also out-of-the-box support for today's most relevant programming paradigms, like structured, object-oriented and functional, but unlike some popular languages, none of these are enforced. This means, once a beginner has grasped the very basics of programming, the teacher can easily proceed to teach a particular paradigm still using Python.