Name

DEV-05: Generate code whenever possible and appropriate.

Synopsis

Life is short—and way too much of it is consumed by time spent in front of a computer screen, moving digits with varying accuracy over the keyboard. Seems to me that we should be aggressive about finding ways to build our applications with an absolute minimum of time and effort while still producing quality goods. A key component of such a strategy is code generation: rather than write the code yourself, you let some other piece of software write the code for you.

Code generation is particularly useful when you have defined standards you want everyone to follow. You can try to get developers to conform to those standards with a “stick” approach: follow the standards, or else! But a more effective way to get the often anarchistic, or at least highly individualistic, programmer to follow standards is to make it easier to follow than not follow those guidelines. See Section for specific demonstrations of this “carrot” approach.

In addition to helping to implement standards, code generation comes in handy when you have to write code that is repetitive in structure (i.e., it can be expressed generally by a pattern). For example, the kind of code you write to determine if there is at least one row in a table for a given primary key is the same regardless of the table (and primary key). Wouldn’t it be nice to be able to call a procedure that queries the table structure and key from the data dictionary and generates the ...

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.