Home

Return of boolean expressions should not be wrapped into an if-then -else statement

Description

    The rule "Return of boolean expressions should not be wrapped into an if-then -else statement" in PL/SQL code means that boolean expressions should be returned directly without the need for an if-then-else statement. This is because boolean expressions already return either true or false, so there is no need to wrap them in an if-then-else statement. This makes the code more efficient and easier to read.

Key Benefits

  • Readability: Return of boolean expressions should not be wrapped into an if-then -else statement as it increases the readability of the code by avoiding unnecessary nesting.
  • Maintainability: Return of boolean expressions should not be wrapped into an if-then -else statement as it makes the code easier to maintain and debug.
  • Performance: Return of boolean expressions should not be wrapped into an if-then -else statement as it improves the performance of the code by avoiding unnecessary branching.

 

Non-compliant Code Example

DECLARE flag BOOLEAN := score < 35;
--IF student have score more then 35. 
BEGIN
IF flag THEN                --Non compliant code (Return of boolean expressions is wrapped into an if-then -else statement)
	RETURN FALSE;
ELSE
	RETURN TRUE;
END IF;					
END;

Compliant Code Example

BEGIN
	RETURN score < 35 ;             --Compliant code
END;
Visual Expert 2024
 VEPLSQLRULE127