Home

Unary prefix operators should not be repeated

Description

    The rule "Unary prefix operators should not be repeated" states that unary prefix operators should not be used more than once in a statement. Unary prefix operators are operators that operate on one value, such as the minus sign (-) or the plus sign (+). Repeating these operators can lead to confusion and errors in the code, and should be avoided.

Key Benefits

  • Consistency: Unary prefix operators should not be repeated, ensuring a consistent approach to coding.
  • Readability: Unary prefix operators should not be repeated, improving readability of code.
  • Maintenance: Unary prefix operators should not be repeated, making it easier to maintain code.

 

Non-compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF NOT NOT (@Number > 100)   --Non compliant code (Unary operator is repeated)
    PRINT 'The number is greater then 100.';  
ELSE
    PRINT 'The number is less then 100.';

Compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF NOT (@Number < 100)   --Compliant code
    PRINT 'The number is greater then 100.';  
ELSE
    PRINT 'The number is less then 100.';
Visual Expert 2024
 VETSQLRULE16