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

STYL-01: Adopt a consistent, readable format that is easy to maintain.

Synopsis

Your code should have a “signature,” a style that is consistent (all your programs look the same), readable (anyone can pick up your code and make sense of it), and maintainable (a minor change in the code shouldn’t require 15 minutes of reformatting).

Ideally, everyone in your organization would adopt a similar style, so that everyone can easily understand everyone else’s code. This can be tricky, as programmers sometimes take a dogmatic approach to such issues as size of indentation and use of whitespace.

You have two options regarding coding style:

  • Find or write a set of guidelines, and then try as hard as you can to follow (and get your group to follow) those guidelines. See Section for a sample document.

  • Use a tool to automatically format your code for you. The dominant code formatter for PL/SQL is currently PL/Formatter from RevealNet (see Section ). This product is not only available standalone, but is also integrated into many popular integrated development environments (IDEs).

I strongly recommend that you use PL/Formatter or some other “pretty print” tool. It is quite liberating to write code without any concern whatsoever for how it looks: I focus completely on the logical flow and then press a button a moment later to turn it into readable, attractive code.

Example

Here is a package specification that has some clear problems: all uppercase, no indentation, no whitespace:

CREATE OR REPLACE ...

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