# Weird Operators

I have ‘equal-equal’ imprinted into my mind lol. ‘Equal’ just doesn’t make any sense to me anymore, for some reason

Useless programming language trivia:

Some languages actually do have `=` as the ‘is equal to’ sign.
Usually those languages use something like `:=` (e.g. ALGOL, Pascal) or `<-` (e.g. R) for assignment.
It’s definitely less popular though.

Technically it’s also possible to use the `=` for both (I’ve written a parser that does that before), but I don’t know of any languages that actually do that offhand.

1 Like

That is quite the questionable ‘equal-equal.’

That’s not the equality test, that’s the assignment operator.

E.g. (Pascal)

``````if (i = 4) then
begin
x := 10
end;
``````
1 Like

Why don’t they just make it the other way around? I guess I could see a colon being somewhat of an ‘is equal to’ thing.

Probably to make it more in-keeping with what people are taught in maths.

It’s easier to introduce a new operator for assignment than to teach people to learn that `=` now means ‘assignment’ and `==` should mean ‘equals’ because it’s harder to unlearn what you’re used to if you’ve never used anything else.

Things get even weirder when you consider not-equal operators too.
Some use `!=`, some use `/=` (which is ‘divide by’ in some languages), and some use `<>` (which also sometimes has a different use in other languags).

C++20 added the `<=>` - the three-way comparison operator. It:

• Evaluates to a negative value if the left hand side is less than the right hand side.
• Evaluates to a positive value if the left hand side is greater than the right hand side.
• Evaluates to zero if both sides are equal.
1 Like