top | item 26912561

C++ Alternative Operator Representations

50 points| signa11 | 4 years ago |en.cppreference.com | reply

26 comments

order
[+] joisig|4 years ago|reply
Back in 2009 or so, I and a few others ran a Google-internal April Fool's prank based on this.

We auto-generated a humongous pull request for the Chromium source code and sent it out for review by all the various source code "owners" (super reviewers) who would need to sign off.

The change used the alternate encoding for curly and square brackets, claiming the original characters were inaccessible on an Icelandic keyboard layout (which is half true, and there were quite a few of us Icelanders around) and that therefore, to be inclusive, we would like to standardize on the alternative representation.

Good fun, although I don't remember if a single one of the reviewers was fooled :)

[+] wmu|4 years ago|reply
I often use "not", "and", "or" to clearly express logical conditions. Bit operations look better as cryptic symbols "&", "|" and "~". :)
[+] MaxBarraclough|4 years ago|reply
A valid opinion for language design, but when writing real C++ code, I'd stick to the usual way of doing things.

English language keywords aren't always great for readability in my opinion. Ada's and then / or else syntax, for instance. They're the short-circuit syntax, whereas and and or give eager evaluation. [0] You can't determine that just from the syntax though, so it ends up being no less cryptic than using strange symbols the way C++ (typically) does.

[0] https://en.wikibooks.org/wiki/Ada_Programming/Operators#Shor...

[+] usefulcat|4 years ago|reply
I do this too, as I find it a bit more readable. Also, I find it handy to reserve '&&' exclusively for rvalue references.
[+] bombela|4 years ago|reply
Same. `a and b or c` reads nicer than `a && b || c` to me.

And I find its harder to typo and misread it:

`a && b || c` vs `a & b | c`

`a and b or c` vs `a & b | c`

[+] ncmncm|4 years ago|reply
Essential!

"If new true friend not protected for explicit private union, break case and try using this."

I often write

  if (not ... 
for emphasis. The "bitand" etc. are similarly useful where the operator might otherwise be mistaken for "&&" or, particularly, "||".

The only one that is an unfortunate choice is "compl", which just looks strange. When I feel a need to call attention to use of "~", I define a lambda "bitwise_not(bool)". But rarely.

[+] tyingq|4 years ago|reply
In Perl, the english operators for and/or/etc have lower precedence than the symbolic ones.
[+] nikhilsimha|4 years ago|reply
This blew my mind. Mostly because I haven't come across this during 8 years of c++ use for professional/competitive programming.
[+] WalterBright|4 years ago|reply
I've never seen anyone use these since they appeared in the spec decades ago. They're as pointless as trigraphs, which I've never seen in the wild either.
[+] tirrex|4 years ago|reply
What is the purpose of this? Does anybody find these more readable?
[+] WalterBright|4 years ago|reply
It's like Van Halen and the brown M&Ms thing. It determines if the author of a C++ lexer, syntax highlighter, etc., read the Standard. Try splitting a digraph with \ and a newline.
[+] detaro|4 years ago|reply
> What is the purpose of this?

Its explained in the first two sentences of the page.

[+] slaymaker1907|4 years ago|reply
I like the use of "not" because it stands out more clearly than "!". "if (not (x and y))" seems more readable to me than "if (! (x && y))".