Why Python is a great language for teaching beginners in introductory programming classes May 2007
This article presents reasons for why I feel that Python is a great first language to teach students about computer programming (see this related article for more of my views on introductory programming courses). I've developed and refined some of these hunches through my experiences in teaching Python to beginners. In a nutshell, all of my assertions reinforce my belief that most beginner programmers don't care at all about Computer Science or programming language theory, but rather simply want to get the computer to do what they say with as little overhead and boilerplate code as possible. The less code they need to write, the less errors and bugs they might encounter; the less errors and bugs they encounter, the less likely they are to become frustrated in those crucial early days and give up on programming altogether. I think that Python is superior to many other languages for teaching introductory programming because it allows the student to focus less on details such as types, compilers, and writing boilerplate code and more on the algorithms and data structures relevant to performing their intended tasks (similar arguments could be made for languages such as Ruby). Here are some specific Python features that make it great for teaching beginners to program: No need to declare the types of variablesWhen a student first learns to program in a statically-typed language
such as C++ or Java, usually the first lines that he/she must write are
variable declarations like Run-time type errors rather than compile-time type errorsCompile-time type errors annoy students to no end. It's better to at least let their program run and do SOMETHING rather than fail to compile and do NOTHING. In production-quality mission-critical code, a compiler with strict static type checking is vital in order to reduce the incidence of run-time type errors, but students aren't writing code for nuclear reactors—they're writing 20-line toy programs. At least let their programs run and have them figure out what went wrong at run-time! Sometimes execution can get pretty far before a run-time type error occurs, and the student is likely to have a decent intuition about the source of the error. It's demoralizing to be a beginner who just wants his code to run and do something (even if it doesn't behave perfectly), only to find out that this mysterious tyrant called a 'compiler' refuses to turn his code into an executable program. Ideally, students should be able to run their programs as frequently as possible—the more iterations of the edit-debug cycle they can squeeze in during a programming session, the more motivated they will be to learn. (The article Strong Typing vs. Strong Testing by Bruce Eckel discusses the advantages of a dynamically-typed language in producing higher-quality code even when used by veteran programmers.) The
|