Tuesday, January 13, 2015

But I Have The Same as Him

One thing I hear a lot is “I have the exact same code and someone else and theirs work and mine doesn’t.” The obvious wise guy reply is “if yours doesn’t work then it is not the same.” Students are not huge fans of that reply. Typically this situation occurs because students copy code without understanding it. They don’t realize that code does not exist in nice isolation.

The two most common reasons I see this complaint is that the code depends on variables the student has not defined or there is an identifier mismatch. For example the code uses a variable that has a scope beyond just the method the student is looking at. Usually there is a warning or even an error that would point the student to this answer. For some reason students often want someone else to explain the error message to them.

The identifier mismatch comes into play in a lot of Windows Forms applications. The student whose code does not work has named their objects differently from the student whose code they copied. Students seem to expect the computer to magically understand what object they mean regardless of what they call it. Alas the “do what I mean” instruction seems not to have been implemented yet.

I try to impress on students that names matter and that spelling names correctly matters. Somehow it seems to take a while to stick.  Students are used to other people understanding what they mean even when they have trouble expressing themselves. Computers are not very good at that though.

1 comment:

Garth said...

My first year of teaching Python some kids had Python 2, some had Python 3. The exact same code did not work on both. Live and learn. We all went to Python 2. It is amazing what the first year of teaching a language does to refresh the troubleshooting skills. This year I will make sure they are all using Python 3 and the same editor.