Hi, this is my first topic, and I am sorry if I selected the wrong category ![]()
This is the C++ rule which I call in question:
Alternative operators should not be used (cpp:S3659)
Even though the C++ standard defines both “Primary” and “Alternative” operators, it is not a good idea to use the alternatives. Developers seeing an alphabetical name expect a variable, a function, a class, a namespace… in short, anything but an operator, and they will be confused at best by code that uses such operators.
Primary Alternative && and &= and_eq & bitand | bitor ~ compl ! not != not_eq || or |= or_eq ^ xor ^= xor_eq
For the boolean operators, I think there are GOOD reasons why the alternative operators (not, and, or) should be used instead of the primary ones (!, &&, ||) :
-
not,and,orare not confusing for people familiar with boolean logic (which every software developer should be). -
not,and,orare used in languages like python, which more and more C++ developers are familiar with. -
In C++, boolean operator
!is so short that the reader can miss it and misunderstand the code
=> usingnotsolves that issue. -
In C++, boolean operator
&&can be confused with bitwise operator&
=> usingandsolves that issue. -
In C++, boolean operator
||can be confused with bitwise operator|
=> usingorsolves that issue.
Thus I think that this rule should NOT apply to the 3 boolean operators.
If this is too controversial, then I suggest that the 3 boolean operators should at least have their own rule. That new rule could :
- have a text explaining both the PROs and CONs ?
- not be included in the “SonarWay” ?
- have a lower default severity (currently: high) ?