Things I like about Pascal [part 1]: == ≠ =

One of the things that pleases me no end about Pascal, like Algol before it, is its use of = to mean =, and not as an assignment operator. For that we have :=.

Dunno if it's my maths background, but I find languages that use the equals sign as an assignment operator to be really, really annoying.

Now good old BASIC gets it right, in that it uses = to test for equality but combines = with the LET prefix for assignment. As in:

LET x = 42

You know, just like you do in maths. Except that many BASIC implementations make LET optional!

But in the curly brace languages (and others), the misuse of = irritates me beyond reason. Especially so when they then go and define == to mean "is equal to" when there's a perfectly good = sign just begging to be used. I find this ridiculous - and I'm in good company:

A notorious example for a bad idea was the choice of the equal sign to denote assignment. It goes back to Fortran in 1957, and has blindly been copied by armies of language designers. Why is it a bad idea? Because it overthrows a century old tradition to let “=” denote a comparison for equality, a predicate which is either true or false. But Fortran made it to mean assignment, the enforcing of equality. In this case, the operands are on unequal footing: The left operand (a variable) is to be made equal to the right operand (an expression). x = y does not mean the same thing as y = x.

Niklaus Wirth, Good Ideas, Through the Looking Glass

If a language doesn't want to use LET, it does makes sense to use different operators for assignment and equality, if only to help the compiler. But why get them the wrong way round and end up using two operators, neither of which make sense? Given that  isn't available on most keyboards then Pascal's good old := operator seems to be a reasonable choice, although personally I'd have preferred <- (as in R).

And, AND

What's all this mess with ===? It doesn't even mean the same thing across the different languages that use it - see here for an explanation.

Why doesn't Pascal have such an operator? Strict typing perhaps?

Where did == originate?

It seems that the first use of = as an assignment operator may have been as far back as in Superplan [1951],  but where does == come from? I've traced it back to B [c1969], but was there an earlier language that used it? Please comment if you know.

Even though B was based on BCPL, the latter used the := assignment operator. This was changed to = in  B, so the equality operator was changed from = to == as a consequence. Marvellous!

What do you think?

I know there are some others who find this misuse of the = sign annoying, but what about you? Comments please!


Comments

Popular posts from this blog

Initialising dynamic arrays

Deleting elements from a dynamic array

New String Property Editor Planned For RAD Studio 12 Yukon 🤞