G-2410: Try to use boolean data type for values with dual meaning.
Reason
The use of true
and false
clarifies that this is a boolean value and makes the code easier to read.
Example (bad)
1
2
3
4
5
6
7
8
9
10
11
12
13 | declare
co_newfile constant pls_integer := 1000;
co_oldfile constant pls_integer := 500;
l_bigger pls_integer;
begin
if co_newfile < co_oldfile then
l_bigger := constants_up.co_numeric_true;
else
l_bigger := constants_up.co_numeric_false;
end if;
do_something(l_bigger);
end;
/
|
Example (better)
1
2
3
4
5
6
7
8
9
10
11
12
13 | declare
co_newfile constant pls_integer := 1000;
co_oldfile constant pls_integer := 500;
l_bigger boolean;
begin
if co_newfile < co_oldfile then
l_bigger := true;
else
l_bigger := false;
end if;
do_something(l_bigger);
end;
/
|
Example (good)
| declare
co_newfile constant pls_integer := 1000;
co_oldfile constant pls_integer := 500;
l_bigger boolean;
begin
l_bigger := nvl(co_newfile < co_oldfile,false);
do_something(l_bigger);
end;
/
|