Home

Variables should not be self-assigned

Description

    The "Variables should not be self-assigned" PowerBuilder code rule states that variables should not be set to the same value they already contain. This means that any assignment statement that assigns a variable to itself should be avoided, as it is redundant and can lead to confusion and errors. Self-assignment can also lead to unexpected results, as the value of the variable may not be what was expected. For example, if a variable is assigned to itself within an if statement, the value of the variable may be changed even if the if statement condition is not met.

Key Benefits

  • Reduced complexity : Less complexity in the codebase as variables are not self-assigned.
  • Increased readability : Easier to read and understand existing code as variables are not self-assigned.
  • Improved maintainability : Easier to maintain existing code as variables are not self-assigned.
  • Reduced errors : Fewer errors in the codebase as variables are not self-assigned.

 

Non-compliant Code Example

function string testCall (string cnt)

cnt = cnt //Non compliant code (Variable is self-assigned)

return cnt

end function
Visual Expert 2024
 VEPBRULE41