JujuScript & Operator Conventions
Have made available for download a "compiled" version of my JujuScript calculator, which got a bit of a fix-up with some recent JujuScript changes.
JujuScript is drifting further away from pure C/C++ syntax, and it’s kind of a relief because it was never 100% compatible anyway. It’s nice to not have to conform. Still there are areas I have to be careful about, such as operator precedence, where it would be kind of insane to break with C standards.
That said, I do think that C/C++ operator conventions* are annoying for the following reasons:
- There is no logical XOR operator, and the obvious choice for it [^^] means nothing. I can’t believe they didn’t add this for C++. Without it we must explicity cast the operands to boolean as in ((bool)a ^ (bool)b) .
-
The bitwise AND, OR and XOR operators have higher precedence then their logical counterparts, but still fall below comparison operators. Comparison operators return boolean values, whereas bitwise operators are designed for integers. But the expression (a == b & c) compares a to b first [resulting in a binary value] and then does a bitwise AND with c … and doing a bitwise operation with a boolean is just stupid! To avoid this kind of confusion, I really think the bitwise operators should fall in precedence between arithmetic and comparison operators.
I guess the precedence issue probably had something to do with the evolution of C, and is not the sort of thing you can change without breaking a lot of people’s code, but the ^^ operator has never been used in C, so adding it for C++ would have affected no one.
The only reason I can think of for leaving out logical XOR is to discourage people from relying on implicit casts to bool [and in fact it’s possible that the only reason we even have logical AND and OR is for their short-circuiting behaviour].
Here are some other things I think are strange about C/C++…
__________
* Java uses the same conventions.