Teaching Programming

September 23rd 2008 09:33 pm

I’ve taught programming on-and-off since the 1970s. Most recently I’ve taught some Java and C. If you’re teaching the mechanics of programming to lots of people (not just the few who instantly “get it”) then you must take an incremental approach. You start with simple concepts and mechanisms and work up from there.

In particular, you start with “straight line” programs (no IFs or loops) so students learn about assignment statements, expressions, and output formatting. Get them used to the idea of variables changing in order of execution. Then you introduce IF clauses, comb structures, and bracketing. Finally, start with Do While loops, While loops, and finally, For loops.

I have to thank Richard Kieburtz (I think that’s the name) who used a progression like this in a Pascal programming book I encountered years ago. Too many books (even so-called classics) start with conditionals and loops in Chapter 1. What could they be thinking? It’s not like loops and conditionals are one of those cultural phenomena we all grow up with.

When I introduce IF statements I also introduce flow charting. Personally I think flow charting is too clunky to be used for real software development, and I don’t make students into flow-charters. Some students, however, don’t necessarily understand flow from statement to statement, but they understand those boxes and arrows.

I introduce loops with the Do While loop. This is a no-brainer if you’re demonstrating things with flow charts - the chart for Do While is the easiest of the loops, with just that diamond on the bottom.

Some people might argue that the For loop should be introduced first. I think it’s harder to understand because of the weird 3-part header syntax.

Another thing I do in C: I introduce a simple header file called “inputs.h” to provide input functions: getint(), getdouble(), and getfloat() [the latter is for completeness - we don't ever really use it]. I spent one semester abetting students who tore their hair out over the weirdness of scanf’s & syntax. My functions hide that bit of nastiness, so I don’t have to deal with & till later in the semester.

One nice thing - if you can get through this sequence fast enough, you can slide into just about any textbook out there for the rest (arrays, functions, structs, etc.). This semester I’m using K&R: Kernighan and Ritchie. It’s both authoritative and cheap, which is a rare thing for a ‘textbook’ these days.

I admit that I consider introducing function definitions with the early material. I feel guilty when I make students construct multi-page programs with no functional decomposition. On the other hand, they have to learn about scope and argument passing to appreciate the benefits of functions. That seems easier to teach a little later in the semester.

Posted under Tech Teaching |

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.