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.
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;
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.
If only Arduino had C++20
I suspect it’s possible to configure the compiler to use C++20, but I don’t know if it could be done using the Arduino IDE.
I have done countless programs using both and you get used to it either way. The only thing that sometimes catches me out is if (x=1) instead of if (x==1).