Use of the word 'or' instead of double pipe '||'
-
A bit of a dumb question, but it's hard to google for an answer to this. I inadvertently put the word 'or' in a if statement instead of ||. A code review caught this, but the code worked fine. Is this a bug or a feature of Qt? Here's a simple example:
bool a = true; bool b = false; if (a or b) qDebug() << "hello world";
hello world is printed out!
-
https://en.cppreference.com/w/cpp/language/operator_logical
I personally would flag use of word operators since they are not the c/c++ way, even if allowed. too many folks are trying to make c++ into python these days. gets on my nerves.
-
-
@aconnell
As @Chris-Kawa has written.In fact, there are even more of these "alternative tokens" than
and
&or
. See https://en.wikipedia.org/wiki/C_alternative_tokens for C and https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B for C++, e.g.&
=>bitand
,~
=>compl
. Yuck!Note that these were originally introduced to support input keyboards which for whatever reason lacked the symbol characters C used.
Don't use them!
-
I don't understand all the hate for the alternative tokens, personally I would prefer them over the cryptic characters :D
especially as I work with a Mac and a Windows VM and the character keys are differently mapped for pipe and backslash and tilde etc.
-
@J-Hilk said in Use of the word 'or' instead of double pipe '||':
I don't understand all the hate for the alternative tokens, personally I would prefer them over the cryptic characters :D
Are you serious? You prefer to write code using "features" that 99+% of all existing code/users out there do not use? E.g. witness this question the OP has raised, indicating that he had no idea
or
would work. Or, default MSVC does not support. Maybe it's OK if it's only you who codes --- and you never copy/paste it into a question at stackoverflow!C used nicely obscure symbols to keep the hoi polloi out of programming so that people like me could make a living --- and long may that last! ;-)
-
@JonB it is not a pure C feature, it is officially part of C++ :P
https://en.cppreference.com/w/cpp/language/operator_alternative
and matter of fact, when I read code, I actually read
or
andand
etc and not,pipe pipe
and and
:Pmy personal favourite:
??-
-
@J-Hilk said in Use of the word 'or' instead of double pipe '||':
it is not a pure C feature, it is officially part of C++
Sadly...
-
@J-Hilk said in Use of the word 'or' instead of double pipe '||':
@JonB it is not a pure C feature, it is officially part of C++ :P
https://en.cppreference.com/w/cpp/language/operator_alternativeI know this since I referenced
and https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B for C++
! It's just they were originally introduced in C.
@Christian-Ehrlicher said in Use of the word 'or' instead of double pipe '||':
Sadly...
Exactly!
-
I don't understand all the hate for the alternative tokens
Maybe for few people it is but I wouldn't call it hate in general. Every programming language goes through stages and one of them is hashing out which features become the "canon" of it and which are to be left on the wayside and forgotten. For alternative logic operators this ship has sailed couple of decades ago and there's absolutely no value in trying to turn it around. Someone liking this or that syntax more is irrelevant at this point. Very few people know about this feature, even fewer use it and it's almost never being taught. Even if you like it the best thing to do is let it die its natural death of obscurity, so that it can be removed at some point, like trigraphs were in C++17 after a looooong time. A simpler language with fewer syntactical options to do the same thing in different ways is far more valuable. I would gladly send this feature to a chopping block just because it's redundant at this point, not because I dislike the syntax.
-
@fcarney said in Use of the word 'or' instead of double pipe '||':
2[array] = 17;
Bad engineer! No cookie!
-
@Kent-Dorfman you owe me a clean cloth to clean my display <3
-
@fcarney C++ has grown to be a very versatile language. It can be used to solve "real world" engineering problem, teach someone to code, enter one of these for fun code contests and much more. That type of code is good for one of these tasks at least :)