Home

GOTO statements should not be used

Description

    The "GOTO statements should not be used" PowerBuilder code rule states that GOTO statements should not be used in PowerBuilder code, as they can lead to code that is difficult to read and maintain. GOTO statements cause code to become "spaghetti code" - code that is difficult to follow and understand. Instead of using GOTO statements, it is better to use structured programming techniques such as looping and branching. These techniques make code easier to read and maintain, and can help to reduce errors in the code.

Key Benefits

  • Ensures Code Quality: GOTO statements should not be used as it makes it harder to read and maintain the code. This ensures that the code is of a higher quality.
  • Reduces Errors: By avoiding GOTO statements, it reduces the chances of errors being introduced into the code. This makes the code more reliable.
  • Improves Code Readability: By avoiding GOTO statements, it makes the code more readable and easier to follow. This makes it easier to debug and maintain the code.

 

Non-compliant Code Example

function integer calculateSteps(integer step)

integer totalSteps = 0

	if step < 0 then
		goto negative //Non compliant code 
	end if

totalSteps = totalSteps + step

negative: 
    totalSteps = 0

return totalSteps

end function

Compliant Code Example

function integer TestFunctionCall (integer step)

boolean	flag = false //Compliant code 

integer totalSteps = 0

if step < 0 then
	flag = true  
end if

IF flag THEN
   totalSteps = 0
ELSE
   totalSteps = totalSteps + step
END IF

return totalSteps

end function
Visual Expert 2024
 VEPBRULE43