PowerBuilder
All branches in a conditional structure should not have exactly the same implementation
Description
The "All branches in a conditional structure should not have exactly the same implementation" PowerBuilder code rule states that all branches in a conditional structure should have distinct implementations. This means that each branch should have its own distinct logic and code, rather than having the same code repeated across multiple branches. This helps to ensure that the code is clear and easy to read, and that the logic of the code is sound and consistent. Additionally, it helps to avoid potential errors that could arise from having multiple branches with the same implementation.
Key Benefits
- Flexibility: All branches in a conditional structure can be implemented differently, allowing for more flexibility when making decisions.
- Efficiency: Different branches can be optimized to take advantage of different conditions, making the overall process more efficient.
- Robustness: Different branches can be tested for different conditions to ensure that the overall process is robust.
Non-compliant Code Example
function string TestFunctionCall (string cnt) if cnt = 1 then cnt = 'B'; elseif cnt = 2 then cnt = 'B'; //Non compliant code (Else if section is having same implementation as below) else cnt = 'B'; //Non compliant code (Else section is having same implementation as above) end if return cnt end function
function int TestFunctionCall() int @count = 1 if aa_value1 < aa_value2 then return @count elseif aa_value1 = aa_value2 then return @count //Non compliant code (Else if section is having same implementation as below) else return @count //Non compliant code (Else section is having same implementation as above) end if end function
Compliant Code Example
function string TestFunctionCall (string cnt)
if cnt = 1 then
cnt = 'B';
else
cnt = 'A'; //Compliant code
end if
return cnt
end function
function int TestFunctionCall()
int @count = 1
int @count1 = 0
if aa_value1 < aa_value2 then
return @count
elseif aa_value1 = aa_value2 then
return @count1 //Compliant code
end if
end function