PowerBuilder
IF statements should not be nested too deeply
Description
This rule states that IF statements should not be nested too deeply. This means that when writing code, the programmer should avoid writing nested IF statements that are too complex and difficult to read. Nested IF statements are when one IF statement is placed inside another IF statement. Too much nesting can make code hard to read and difficult to debug. To avoid this, the programmer should try to limit the amount of nesting and use other programming techniques to keep the code clear and readable.
Key Benefits
- Reduced complexity - IF statements should not be nested too deeply helps reduce complexity of code.
- Easier to read - Keeping IF statements shallow makes the code easier to read and understand.
- Faster execution - Shallow IF statements execute faster, making the code run more efficiently.
Non-compliant Code Example
function string TestFunctionCall (string cnt) IF x > 1 THEN IF x > 2 THEN IF x > 3 THEN IF x > 4 THEN //Non compliant code (Nested loop should be less then 4) IF x > 5 THEN //Non compliant code (Nested loop should be less then 4) cnt = "x > 5" END IF; END IF; END IF; END IF; END IF; return cnt end function
Compliant Code Example
function string TestFunctionCall2 (string cnt)
IF x > 5 THEN //Compliant code
cnt = "x > 5"
END IF;
return cnt
end function