Monday, February 15, 2010

They teach programming, don't they?

One evening, many years ago, when I was in college, I had an epiphany. Maybe not as enlightening as the epiphany I had while watching "The Mummy Returns"  many years later, but that's a story for another day.

While working on some class project, I realized that soon, within a couple of  years, I'd be working for a real company and I'd actually have to write code that REALLY works. Not just something that gets past the grader, or answers all the test cases. Something well designed, well written, maintainable, and reliable.  Scary thought.

I've thought about this a lot since I started teaching computer science. We teach programming languages, algorithms, and assign projects. Maybe the students hear something like "comment your code," or "use good variable names," but we never really give them the tools to take a project from description to completion.

Too often young programmers rush to the keyboards and write copious amounts of code without any plan and with little discipline. In short they do everything they can to set themselves up for a difficult road ahead.

There are probably a number of reasons for this. When we teach introductory  programming, assignments are so short and simple that we can't easily model good programming techniques, and if we do, it's difficult to get students to "buy in" since it's hard for them to see the value. As complexity increases, we're faced with limited time to actually cover the prescribed course content, leaving little room for a protracted unit on "program development."

I'm certainly not going to be so bold as to say that I have the answer to the problem, but I've tried some things to help address it.

We'll take a few class days to take a project from beginning to end. Something that can be done incrementally but isn't particularly difficult.

This semester, I attempted this with my AP students. We wrote a series of text filters in Java. I lifted the topic from Kernighan and Plauger's "Software Tools." We wrote versions of character count, word count, detabbing a file, run length encoding and a simple version of tr. Nothing too heavy, but it allowed us to focus on the development piece rather than coming up with clever algorithms and data structures (which is what the rest of the class is for). The problem may be a little contrived, but I hope the benefits outweighed any issues with the choice of problem.

We start by talking about the importance of understanding the problem, which includes finding out what "the client" wants and not making our own assumptions. Some times, I try to leave a little ambiguity to give us a platform to discuss the "what the client wants" issue.

From there comes design, which might be mixed with writing some code to make sure we understand certain aspects of the problem and the environment we'll be working in.

Once we have a design and a plan we can start incremental development. This is what I think is most important for the youngsters. I try to model and emphasize the idea of coding one "concept" at a time. Frequently testing that concept and only moving on once it's completed.

I'll also talk about things that have worked for me along the way. I always like to put consistent comment blocks at the top of my functions, trying to keep functions a "screen length" or shorter, my preferences for naming, indentation, etc. Of course, I'm careful to emphasize that my way works for me, but it's just one approach. I try to present alternatives when possible.

Other ideas I try to emphasize is actually reading ones code and having others read it. Last semester I experimented with "pair programming" and while I have no idea how good it is as a professional development technique, I like it from a pedagogical point of view.

I think presenting these ideas while actually developing the project helps to drive in the concepts.

I'd like to think adding units like this helps to develop stronger programmers. Any teachers out there -- your thoughts?







In an unrelated note, yesterday was valentines day. We don't really do anything to celebrate it, but in anticipation of her new loom, Devorah had to clear off some room in the apartment. She stumbled upon love letters sent between my parents back in the fifties. If you'd like a small taste of the past, you can see here post on squidknits here.

Although we have gained all this immediacy with the electronics age, it sometimes feels that somethings been lost.

3 comments:

  1. Z,

    With respect to the second paragraph:

    I find that I'm going through the opposite experience in class now. Stuy CS projects had about the same minimum requirements as the projects I do now for equivalent classes, but the specs (and deadlines!) allowed for so much more.

    My next C class's programming assignment, for example, asks to create a few specific structs with names given in the specs, write other given functions, and print some things out. As far as I can tell, it's going to be automagicatically graded by comparing output.

    How am I going to find a job now?

    ReplyDelete
  2. Z,

    I am almost finished with my first year teaching IB CS and I think the dossier component of the IB really addresses this. Students have to submit a significant project for 35% of their final IB grade and this involves a detailed Analysis (where evidence of interaction with an end-user is required) and Design stage. The coding part is only 25% of their grade. In the end, they submit a paper that's about 60 - 100 pages long and looks like this:

    http://ibcomp.fis.edu/projects/quizTacToe/quizTacToeDocs.pdf

    I think the students learn a lot from this.

    -melissa

    ReplyDelete
  3. I think that by designing curriculums that force students to re-use their existing code would be a step in the right direction. Stuy did this with the "Pet Store" project in AP. If I remember correctly, we were told to write a bunch of different "pet" classes, and then write "pet stores" that sold the pet objects.

    We've also had to re-use a lot of our code in the Graphics class, but I think that's just because my group is creating a custom project in python, and not using the framework you've set up.

    Programming practice is an interesting topic. It probably deserves a course on its own. I've only been able to _really_ learn it through internships.

    ReplyDelete