PowerBuilder

Jump statements should not be followed by dead code

Description

    The "Jump statements should not be followed by dead code" PowerBuilder code rule states that any jump statement (such as a "goto," "return," "exit," or "exit loop") should not be followed by code that will never be executed. This is considered bad programming practice, as it can lead to confusion and errors. It is best practice to ensure that any code following a jump statement is necessary and will be executed.

Key Benefits

  • Reduced complexity: Jump statements should not be followed by dead code rule reduces the complexity of code by eliminating unnecessary code.
  • Improved readability: Jump statements should not be followed by dead code rule improves the readability of code by making it easier to understand.
  • Increased efficiency: Jump statements should not be followed by dead code rule increases the efficiency of code by removing redundant code.
  • Enhanced maintainability: Jump statements should not be followed by dead code rule enhances the maintainability of code by making it easier to update and modify.

 

Non-compliant Code Example

function string TestFunctionCall (string name)

integer A = 1, B = 1
DO WHILE A <= 15
      EXIT; //Non compliant code (Containing dead code, statement below EXIT will never get execute)
      A = (A + 1) * B
LOOP

messagebox('Success','test finished ')

return name

end function
function string rule32InValidTest (string name)

return name; //Non compliant code (Containing dead code, statement below RETURN will never get execute)

@count = 1 

end function

Compliant Code Example

function string TestFunctionCall (string name)

integer A = 1, B = 1
DO WHILE A <= 15
      A = (A + 1) * B
LOOP

messagebox('Success','test finished ')

return name

end function
function string rule32InValidTest (string name)

return name; 

end function
Visual Expert 2024
 VEPBRULE39