Home

Boolean checks should not be inverted

Description

    The PowerBuilder code rule "Boolean checks should not be inverted" states that a Boolean check should not be written in a way that would cause it to evaluate to the opposite of what is intended. This means that when writing code, it is important to be aware of the logical structure of the code and ensure that any Boolean checks are written in the correct order. This will ensure that the code behaves as expected and does not produce unexpected results.

Key Benefits

  • Error Prevention: By avoiding inversion of Boolean checks, errors can be prevented from being introduced into the code.
  • Ease of Maintenance: Code that is not inverted is easier to understand and maintain.
  • Performance: By avoiding inversion of Boolean checks, performance can be improved, as the code is simpler and faster to execute.

 

Non-compliant Code Example

function string TestFunctionCall(string cnt)

if NOT cnt <> 1 then //Non compliant code
    messagebox('cnt not equals to 1')
end if

if NOT(cnt = 1) then //Non compliant code
    messagebox('cnt equals to 1')
end if

if NOT cnt then
    messagebox('not cnt')
end if


return cnt

end function

Compliant Code Example

function string TestFunctionCall(string cnt)

if (cnt = 1) then //Compliant code
    messagebox('cnt not equals to 1')
end if

if (cnt <> 1) then //Compliant code
    messagebox('cnt equals to 1')
end if

if NOT cnt then
    messagebox('not cnt')
end if

return cnt

end function
Visual Expert 2024
 VEPBRULE57