问题
leisure/curiosity question as implied in the title.
I personally prefer the new operators as to make code more readable in my opinion.
Which ones do use yourself? What is your reason for choosing one over the other one?
also Emacs highlights those operators differently so I get more visual feedback when looking at the screen. I know the old operators can be highlighted as well but the ISO646 highlighted by default
回答1:
I won't use the alternative operators as they cause more confusion then clearity in my opinion.
If i see an alphabetical name i expect a namespace, class, variable, function or a function style operator - the common operators divide this intuitively into sequences for me. The alternative style just doesn't fit into the C/C++ world for me.
Also, while Greg has a point regarding people new to C or C++, you get used to it pretty soon - i have no problems spotting !
anywhere.
回答2:
I don't think I have ever even seen C/C++ source code that actually uses the alphabetic operators. To me, it just looks strange; very un-C-ish.
回答3:
I prefer to use not
instead of !
because it's a lot more readable:
if (not condition()) {
}
versus
if (!condition()) {
}
The !
kind of gets lost in there. Of course, this must be avoided (or #define
d) when writing code intended to be portable.
However, and
and or
don't do much for me, so I don't use them.
回答4:
Are you referring to the alternative tokens originating from iso646.h?
They are from C and it's very uncommon to see, therefore likely to be less readable by most. I'm sure if we had been "raised" with these keywords they'd be more common, since they read like English better.
Then again, &&
lets non-English speakers say "and" in their native tongue. (Not that this was a concern in the keywords in the first place.)
回答5:
I use the old ones.
Reason: I coded in Perl for a while and the operators have different precedence depending on if they're the spelled-out variant or not. I ran into a couple of bugs because of this and since then I always use &&
, ||
and !
over the spelled out variant for any language that has them.
回答6:
Alternative tokens for logical (and not only logical) operators, like and
, or
, not
etc. have nothing to do with C++ specifically. They were present in C as well, virtually from the very beginning. If you like to use them in your code, you are free to do so, but don't be surprised if people see this practice as rather unorthodox. Normally people use traditional designators for these operators (e.g. &&
, ||
and so on) in both C and C++ code.
来源:https://stackoverflow.com/questions/1703979/which-c-logical-operators-do-you-use-and-or-not-and-the-ilk-or-c-style-oper