Friday, July 15, 2005

Dont ever try to redo the thing !

Sometimes, we will may write conditional statements that may be valid still, and are unnecessary and cumbersome. Such statements often reflect a lack of understanding about how you can and should use language structures.
for exempli gratia :

DECLARE
boolean_variable BOOLEAN;
BEGIN
IF boolean_variable = TRUE
THEN
...
ELSIF boolean_variable = FALSE
THEN
...
END IF;
END;


what we are gonna acheive by redoing the thing already
the compiler is doing for us.
( havent u heard of word like " never try to re-invent the wheel " ) ;;)

here goes the simplification of the code .

DECLARE
boolean_variable BOOLEAN;
BEGIN
IF boolean_variable
THEN
...
ELSIF NOT boolean_variable
THEN
...
END IF;
END;

It is implicit that the what the boolean is going to do for us,
one more classic example for the inefficient use of the boolena variable we can find at here;

IF DOB '<' SYSDATE THEN
celebrated := TRUE;
ELSE
celebrated := FALSE;
END IF;
here u can see the idea behind this is to find the boolean, has it been celebrated.
may be simple thing here to notice will be.
there are only two state for the conditional statements.
celebrated := DOB '<' SYSDATE;
here watch out carefully, the DOB can be NULL ;
celebrated := NVL( DOB '<' SYSDATE);
The above statement offers a comparable expression ;) is it nt ?
( doing this may make ur code look expressive )

0 comments: