Monday, May 28, 2018

Assumptions, Misunderstandings, and Programming Decisions

My beginning students have big problems with writing decision statements. Boolean expressions are a real problem. Most of the time it is because they expect the syntax of a programming language to be close to how they express things in English.

For example, in English one can say “give me a number between one and 10” and it is pretty clear. When they try to say the same thing in programming language they write something like:


if index >= 1 and <= 10 then
or
if index = 1 - 10 then

Of course neither of the work as students expect. The first gives a syntax error and the second compares index to -9 with is probably never going to happen. Try as I might, there are always some students who get this wrong. It just isn't logical in their minds. They are used to making certain assumptions and filling in some blanks or ambiguities and they expect the computer to do the same. I'm running out of ideas on how to get this across.

The opposite end of the spectrum is when students think something is necessary when it is not. For example, if there are only two options than a simple if/else will work. You do not need and if/else if. I see all sorts of unnecessary comparisons from beginners. Many students get this right away. A few, more than I would like, struggle with this. Generally this sort of code does actually work so it is hard to get students to realize that here is a better way. "But it works!" is all that matters. For someone like me who worked in a time when programmers counted comparisons and had a ready handle on instruction speeds for optimization of memory and performance this is a painful observation.

In some of my classes I have enough time to get into the nitty gritty of this. With my freshmen for whom programming is only part of a quarter it is harder. One of my goals for this summer as I review all of my curriculum is to try to find some more/better/different ways to work on these misconceptions. Parsons Problems may be part of the answer. I have experimented a little with them this year and they seem to help. Maybe some animations will work if I can figure out have to make them. I've already written more specifically about these issues in the book I have been writing for my classes.

I could still use ideas. Surely someone out there has solutions to this issue. Any suggestions?

1 comment:

Unknown said...

Classic mathematical compound inequality:
i >= 0 AND i <= 10
can be mathematically written as
0 <= i <= 10
but there is no equivalent in many computer languages.

I would start with not having both limits not depend on the came variable:
num_oranges >= 0 AND num_apples <= 10
Pretty much have to write the code (and the math) very close to the above line.

There is nothing different if both limits are the same variable.