Learning computer programming at the high school/middle school level is often compared to the study of mathematics at the same level. Both require the acquisition of what is basically a new language with their own “words” and syntax, both require a logical, step-by-step thought process and both require patience and perseverance to get half-way decent at either. The problem with this comparison is the differences between mathematics and programming are more significant, from the teaching aspect, than the similarities.
To be good at mathematics often requires intuitive leaps to solve new problems. As a math teacher I see that my best students have the ability to make the leap, then come back and fill in the holes left by that leap, while the average and below average students struggle along trying to rely on rote memorization of previous examples. The good students will have an understanding of the concept behind the math and will have some examples memorized. The average students will have some examples memorized and if a problem varies enough from the example, the student is lost. In programming there can be no intuitive leaps in writing a program. The computer simply does not like them. Examples of code are not memorized, they are cut and pasted. Cut and pasting on a math exam is bad, cut and paste in a programming assignment is expected.
For years I have been trying to teach math kids to think outside the box, while in programming it is all inside the box. Programming does take leaps of intuition, but hopefully not while typing the actual code. I teach my students there are two major phases of programming; design and code. I admit this is a bit simplistic but they get the idea. In the design phase the programmer needs to think smart. This is the phase where you take the concept/idea/assignment/whatever and build a rough outline of how the thing is going to work; what is the input, what is the output, what does the GUI look like, what functions and procedures would help break the program down into component pieces, and so on, are what I consider part of the design phase. Hopefully this is where any leaps of intuition are going to take place. This is also where the big money is made. The code phase is where the programmer is actually hammering on the keyboard try to make the ideas work. This is where the programmer has to think stupid, just like the computer. This is also the job that is usually shipped overseas. Here the programming is consists of using the language that has been somewhat predefined. There is no such thing as writing an original For/Next statement so there is no need to get clever. The clever part was back in the design phase were the For/Next was laid out.
Many of the kids (all right, all of the kids) like to skip the design phase of this whole process. They want to sit down and start hacking some code and see if something is going to work. Now I admit this is my own favorite method of writing programs, it is sort of fun this way but experience has taught me that it is usually not the most efficient method. Beginning programming students simply do not have the experience with years of coding to make this work. In mathematics class I love it when the kids just start trying things, I like to see them experiment and dig through the textbook. When a programming kid starts just trying things I know they do not have a clue what to do and they are going to take forever to get anywhere. One of the big differences using the trial-and-error method in math verses programming is the shear scope or size of the problems. The typical high school math problem is at most one page, the same can rarely be said of a typical programming problem. If the kids try to solve a programming by hacking it the assignment just does not get done in a reasonable amount of time. That design/planning time is critical.
Look at the programming statement “x = x + 1”. Put yourself in the position of an average high school student as you look at this statement. From the high school mathematics point of view this thing makes no sense. For years the kids have been taught x = x, not x + 1. All of the sudden this statement is supposed to make sense? Good luck with that. The better students will pick it up quickly, they can compartmentalize the differences as context requires. The average kid is going to try to continue to apply the algebra rules he/she struggled so hard to learn over the last 4 years or so. The differences like this between mathematics and programming seem minor to us, the teachers and programmers, but to the kid struggling with both they are major confusers.
Programming can be hard and sometimes we, the teachers, make it even harder by not paying attention to the differences in what the students already know and what we are trying to teach them. The logic that a program has to go through, every little step being defined and succinct, is not the easiest way for kids to think. They what to make those jumps in logic and steps so forcing the kids to “think stupid” is counter to their normal thinking. Beginning programmers need to be able to count on their fingers.