Name
STYL-08: Use vertical code alignment to emphasize vertical relationships.
Synopsis
A common code formatting technique is vertical alignment. Here is an example in a SQL WHERE clause:
WHERE COM.company_id = SAL.company_id AND COM.company_type_cd = TYP.company_type_cd AND TYP.company_type_cd = CFG.company_type_cd AND COM.region_cd = REG.region_cd AND REG.status = RST.status;
You should use vertical alignment only when the elements that are lined up vertically have a relationship with each other that you want to express. In the WHERE clause shown here, however, there is no relationship between the right sides of the various expressions. The relationship is between the left and right sides of each individual expression. This is, therefore, a misuse of vertical alignment.
Example
Developers often (and justifiably) use vertical alignment with program parameter lists, as in:
PROCEDURE maximize_profits ( advertising_budget IN NUMBER, bribery_budget IN OUT NUMBER, merge_and_purge_on IN DATE := SYSDATE, obscene_bonus OUT NUMBER);
Vertical alignment allows you to easily see the different parameter modes and datatypes.
Vertical alignment is also handy when declaring many constants, as in:
CREATE OR REPLACE PACKAGE genAPI IS c_table CONSTANT CHAR(5) := 'TABLE'; c_column CONSTANT CHAR(6) := 'COLUMN'; c_genpky CONSTANT CHAR(6) := 'GENPKY'; c_genpkyonly CONSTANT CHAR(10) := 'GENPKYONLY'; c_sequence CONSTANT CHAR(7) := 'SEQNAME'; c_pkygenproc CONSTANT CHAR(10) := 'PKYGENPROC'; c_pkygenfunc CONSTANT ...
Get Oracle PL/SQL Best Practices now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.