2020-06-30 10:16:44 +02:00
Having functions and procedures which take too many parameters decreases the code's readability and usability. It is likely that such a function/procedure is not modular enough, and should be split into several smaller ones.
== Noncompliant Code Example
With the default threshold of 10:
2020-06-30 14:49:38 +02:00
2020-06-30 10:16:44 +02:00
----
SET SERVEROUTPUT ON
CREATE FUNCTION sumWithTooManyParameters( -- Noncompliant, too many parameters
a1 PLS_INTEGER,
a2 PLS_INTEGER,
a3 PLS_INTEGER,
a4 PLS_INTEGER,
a5 PLS_INTEGER,
a6 PLS_INTEGER,
a7 PLS_INTEGER,
a8 PLS_INTEGER,
a9 PLS_INTEGER,
a10 PLS_INTEGER,
a11 PLS_INTEGER
)
RETURN PLS_INTEGER AS
BEGIN
RETURN a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11;
END;
/
BEGIN
DBMS_OUTPUT.PUT_LINE('Sum is ' || sumWithTooManyParameters(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11));
END;
/
DROP FUNCTION sumWithTooManyParameters;
----
== Compliant Solution
----
SET SERVEROUTPUT ON
CREATE FUNCTION sumCorrected(n PLS_INTEGER) RETURN PLS_INTEGER AS -- Compliant
BEGIN
RETURN (1 + n)*(n / 2);
END;
/
BEGIN
DBMS_OUTPUT.PUT_LINE('Sum is ' || sumCorrected(11));
END;
/
DROP FUNCTION sumCorrected;
----
2020-06-30 14:49:38 +02:00
2020-06-30 10:16:44 +02:00
----
----
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]