Skip to content

Latest commit

 

History

History
73 lines (55 loc) · 2.14 KB

ComparisonOperatorRule.md

File metadata and controls

73 lines (55 loc) · 2.14 KB

<-- previous rule | overview | next rule -->

Use consistent set of comparison operators

Replaces textual comparison operators (LT, LE, EQ, NE, GE, GT) with symbolic comparison operators (<, <=, =, <>, >=, >) or vice versa.

References

Options

  • Preferred set of comparison operators: [symbolic (<, <=, =, <>, >=, >)]
  • Replace regular comparison operators with preferred variant
  • Replace obsolete comparison operators (>< => =<) with preferred variant

Examples

CLASS any_class IMPLEMENTATION.
  METHOD use_consistent_comparison_ops.
    IF a EQ b OR c NE d.
      IF a < c AND b > d
               AND b < e.
        IF a LE d AND c GE b.
          result = xsdbool( a <= d OR a GE b ).
        ENDIF.
      ENDIF.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

FORM any_form.
  " these obsolete variants are only possible outside of the object-oriented context:
  IF a >< b AND b => c OR c =< d.
    RETURN.
  ENDIF.
ENDFORM.

Resulting code:

CLASS any_class IMPLEMENTATION.
  METHOD use_consistent_comparison_ops.
    IF a = b OR c <> d.
      IF a < c AND b > d
               AND b < e.
        IF a <= d AND c >= b.
          result = xsdbool( a <= d OR a >= b ).
        ENDIF.
      ENDIF.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

FORM any_form.
  " these obsolete variants are only possible outside of the object-oriented context:
  IF a <> b AND b >= c OR c <= d.
    RETURN.
  ENDIF.
ENDFORM.

Related code