rspec/rules/S1772/rule.adoc
2022-02-04 16:28:24 +00:00

24 lines
692 B
Plaintext

The result of the comparison is the same, regardless of whether the constant is on the left or right-hand side. But following this convention will help pinpoint the occasional error where ``++=++`` (assignment) is substituted for ``++==++`` (comparison).
If the constant is on the right-hand side of the expression in such cases, the code will still compile and run - just not as expected. If the constant is on the left-hand side, the error will be caught at the first attempt to compile.
== Noncompliant Code Example
[source,text]
----
if ( var == constant )
if ( pointer == NULL )
----
== Compliant Solution
[source,text]
----
if ( constant == var )
if ( NULL == pointer )
----