O'Reilly logo

Oracle PL/SQL Best Practices by Steven Feuerstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required