Thursday, June 24, 2010

Using the Equals Symbol for Assignment is Evil

As experienced programmers, we take many things for granted. One example is that no one who is experienced thinks twice about using "=" as the assignment operator. However, I've found that students with absolutely no programming experience have a great deal of difficulty understanding the semantics of assignment. They confuse the assignment operator with "=" as used in a math context. After all, it's the same symbol, isn't it? And, of course, many of the students think that if it's the same symbol as used in math then it must be commutative, right? x = y means the same as y = x in math therefore variable1 = variable2 must be the same as variable2 = variable1, correct? Do you see where I'm coming from?

I try to get around this problem by introducing the concept of assignment using the operator "<-". It does seem to help but only marginally. Once you get into real programming, students have to face the issue and for some it is still just terribly confusing. We use Python at UAT for our introductory language. A major reason was that Python has one of the simplest syntaxes of any programming language. We've tried Java and C++ but major roadblocks are curly braces and semi-colons. I just wish I could get a Python implementation that uses "<-" for assignment instead of "="!

No comments:

Post a Comment