 |
|
PL/SQL Programming Design Standards
Oracle Tips by Jonathan Ingram
|
PL/SQL Programming Design Standards
Developers should design for modularity. Black box is a term often
used in conjunction with modules; each module should perform one (and only one)
function using a defined interface and produce a predictable result. So long as
the interface for a code module is not changed, the code module may be altered
without affecting outside code.
Each module contains one or more routines (and the data structures and
variables needed to support the routines). PL/SQL allows developers to implement
modularity through the use of packages, which can contain procedures and
functions as well as global type, variable, and constant declarations.
Stored functions that use parameters of the IN OUT and OUT
types are not allowed. Stored functions should use only the RETURN
statement to return a value. Developers are encouraged to identify routines that
can be reused. This code can be centralized, tested, and used by other
developers to improve the reliability of system code and to reduce development
time for more complex modules.
Modularity for PL/SQL
If your organization consists of ten or more people, it might be a good idea to
appoint a ?Modularity Ombudsman? who has some experience with SQL and PL/SQL.
The responsibilities of this position include:
? Identifying code
segments that can be reused
? Developing and testing
reusable modules
? Documenting modules and
promoting their use
The modularity ombudsman should also take part in peer review for new modules
to help increase code reuse throughout your project.
PL/SQL Headers
A header should appear at the start of any script, procedure, function,
package body, or package spec. Consider this template header:
-- *****************************************************************
-- Description: Describe the purpose of the object. If necessary,
-- describe the design of the object at a very high level.
--
-- Input Parameters:
--
-- Output Parameters:
--
-- Error Conditions Raised:
--
-- Author: <your name>
--
-- Revision History
-- Date Author Reason for Change
-- ----------------------------------------------------------------
-- 03 JAN 2015 J.Schmoe Created.
-- *****************************************************************
The Usefulness Of PL/SQL Headers
There are some people who dislike headers or feel that a header is a useless
burden to place on a developer. I disagree: At no other point in the code are
provisions made for documenting the overall purpose, logic, and interface of a
module. In my opinion, a header is the most essential documentation for any
piece of stored code.
This is an excerpt from "High Performance Oracle Database
Automation", by Jonathan Ingram and Donald K. Burleson, Series Editor.