11 July 2009

learn to drive before you build a car, learn to read before you write

Although Computer Science as an education is widely available since several decades, many software-development- and in particular programming-jobs are still done by people with a different educational background. Computer Science (CS) departments are struggling to attract as many students as there is demand for educated Computer Scientists, but it seems that the more students they attract (on top of those who would take CS anyways), the more students will fail during their studies. While recruiters say "we need more graduates with CS degrees", professors whine "we are accepting to many students that have no talent."
In programming in particular there seems to be a divide between programming nerds who just seem to understand programming to a point of completing their assignments, while some others always seem to be estrange to programming and struggle even with simple assignments as soon as some variation into problems is introduced. The question which I want to write about here is: how can we teach programming in a way that helps all students?

I have been helping out with teaching programming since I was an undergrad myself. Seeing how awful student programs looked in the first year I helped with the programming lab, I decided to publish some of the best assignment solutions so that the students would have an example to imitate and an idea of how elegant programming solutions can be. Assignment submissions got much better in the second year!

Since that time, Pascal as a beginner's language has been replaced by Java, and Java by Python, but the problems are still the same. I asked one student with a particularly awful program where she he learned the particular construct which she was abusing there. "Oh, that's from my high school teacher."

When after more than half the course was over, the instructor finally taught students about testing. At that point, I started realizing one of the things that went wrong from the beginning: in our course, students were mostly taught to program little functions, but they were never taught how to use those functions properly and how to test them. I could write an entire blog post on the "test first" paradigm of programming, especially it's important in languages like Python which have no static checking whatsoever. But here, let's concentrate on something more fundamental: the actual understanding of programs, what they do, and how they work.

Most students seem to learn by example and the only official good examples of programs that they see in a typical university course are code snippets small enough to fit on a single lecture slide! Given that material, they are supposed to write entire programs with interworking parts. If I contrast that approach with other disciplines of writing, it just seems ridiculous! In literature, students will read entire novels plus probably some secondary literature, before they write essays of their own. In science, students will read a couple of text books plus tens of journal articles before composing a paper of their own. Furthermore, the first writings of students are usually of secondary nature themselves: summarizing, interpreting, or commenting on some primary work (i.e. an essay about a novel, or a paper about some previously published scientific findings). In programming on the other hand, students will get no reading material, and they have to compose primary works starting from their first labs and assignments!

Here are some ideas how to improve this deplorable situation.
  • A large part of the exercises and assignments has to be devoted to reading and understanding programs that have been hand-selected by the instructor as examples of good programming.
  • Possible exercises which train this are: writing documentation for a given (substantial) piece of code, writing test cases for a given program, write an example use for a given program module, and finally, extend a given program by a small feature.
  • Writing of documentation has to be split into external (what does it do) and internal (how does it work).
  • Testing can first be done for a programm that works according to its documentation, and as soon as the students can do this well, let them test and debug an incorrect (but still well-designed!) program.
The important part about all this, is that students have to read and really understand a large corpus of existing code that has specifically been chosen for its good design. Students will then appreciate how easy it is to understand, extend, and debug really well-written code. They will also see how the different programming constructs they know from lectures are best fit together.

I don't know how many of our field's education problems this approach to teaching is going to solve. But I am sure this is the way to go!

0 comments:

Post a Comment