Talking to a computer

The most important tools in our society change not just the way we work but the way we talk and even think. If you’re not convinced, just consider all the different telephony-related phrases that have become an important part of the language: “please hold”, “party line”, “long distance”, “dialed a wrong number”, “hangup”, “off the hook”, “bad connection” are just a few. We adapt to working with new tools by learning new ways to talk about the experience of using those tools.

I’ve adapted to working with computers by translating computer-ese into my own internal understanding, and then doing the translation on-the-fly as I’m working. The more accurate my internal understanding is, the less likely I am to run into syntax errors when I’m programming.

For example, consider the classic ways to teach about the assignment operator (“=”) and the equivalence operator (“==”). First of all, an “operator” is just a symbol that represents something the computer does to data that you provide it with. Use the arithmetic operators (+, -, *, /), to get the computer to do arithmetic, by (for example) adding the value on the left of a plus sign (“+”) to the value on the right side, and then returning the sum. So:

x = 3
y = 9
z = x + y
if z == 12:
    return "3 + 9 = 12"

The first three lines of this program use the assignment operator, “=”, a single equals symbol. Those lines can be read as:

The variable ‘x’ gets the value of the number ‘3’
The variable ‘y’ gets the value of the number ‘9’
The variable ‘z’ gets the sum of x and y.

That’s using the assignment operator. The assignment operator can only work if the thing on the left of the operator is a variable name and the thing on the right of the operator is a value that can be placed into the variable. That’s how variable assignment is done.

Creating a variable and then giving it some value is a fundamental building block for any kind of programming. It’s like creating a (figurative) “box for some value” and then putting something (data) in it. When you want to know what’s in that variable, you can instruct your program to return the value just by referring to that variable by its name.

On the fourth line, though, we use the logical equivalence operator, “==”, or two equals symbols.

This line can be read as “If the value in ‘z’ is equivalent to ’12′”. This type of boolean or logical operator can have only one of two valid values, True or False. These operators allow you to check to see if the value in one variable is greater than the value in another variable, or less than, or equal.

The equivalence operator, “==”, returns True when the values of the things on both sides are equivalent.

The root of the problem is evidenced in line 5. The stuff inside quotes in a program is usually a string–just a bunch of characters that are meant to be printed out. Letters, numbers, symbols, all in a specific sequence. The string that this program returns is a perfectly comprehensible arithmetic truth: “three plus nine is equal to twelve”.

It’s the word EQUAL–and the name of the “=” symbol, which just happens to be “equals”–that causes all the confusion.

My brother, David Loshin, gave me one of the best pieces of advice about programming some years ago, and it’s saved me endless misery:

Think “x GETS some value”, not “x is EQUAL to some value”.

It’s too confusing otherwise.

In other words, the character “=” is just a convenient sign, an abbreviated way of saying, “I’m assigning a value to a variable”, which is another way of saying “the variable gets this value”. You could think of it as “x is equal to this variable”–but that’s not a useful way to think about it when programming.

By extension, when I’m writing code and need to use the equivalence operator, I don’t think to myself as I type, “if x is equal to blah”, I think, “if x is EQUIVALENT to blah”.

I propose a single change to all programming texts and courses: Eliminate the word “equals”, and replace it with something else. No reference to “the equal symbol”, instead, “=” or “the assignment operator symbol”; no more “x equals y”, instead “x and y are equivalent” or “x is equivalent to y”.

The result will undoubtedly speed up the rate of learning by 50%, improve course completion rates by 100%, and improve graduating students’ programming proficiency and ability to get work by 200%.

This entry was posted in computer science, learning to program, Programmer's Tools. Bookmark the permalink.