19 March 2006

Assignment Operator = Considered Braindead

The more I think about it, the more I dislike the use of = for an assignment operator. I suppose in the old days when terseness was almost essential it made sense, or was at least understood to be a sensible compromise. But modern languages should punt it. From the time we're wee tykes we write = to mean "equal"; the stuff on the left of the = is the same as the stuff on the right. So, the first time you see:

a = a + 1

you think (at least, you ought to):

a - a = 1
0 = 1

resulting in a hearty WTF? Of course, you get used to it quickly. Kinda. Sorta. Here is how hideous it's gotten:

If foo = 0 Then
foo = 1
End If

That's Visual Basic. Bletch. Defenders pipe up with "but it eliminates a whole class of errors!" While true in a narrow, twisted sense, this defense is beside the point: = shouldn't be an assignment operator in the first place. What should be? I really don't care. Either of these would be fine:

a := 3
b <- 4

Hell, even this would be OK by me:

c @ 5

We can return = to its rightful, mathematically-meaningful place, and we should.

No comments: