PL/SQL Coding Standards, revisited
- The standards are old, or the person who wrote them is.
- Code formatting is an easy thing to codify and formalise.
Perhaps the source of most wasted energy is formatting keywords. Back in mediaeval times, when the only editors in use were vi or Notepad, or perhaps PFE, this was a pressing issue. But modern editors support syntax highlighting: now that we can have keywords in a different colour there is much less need to distinguish them with a different case.
Personally I prefer everything in lower case; I save about 23 seconds a day from not having to use the [shift] key. But other people have different preferences, and for the sake of the team it is better to have all the source code in a consistent format. But the way to achieve this is with automation not a Word document. SQL Developer, PLSQL Developer and TOAD all have code formatters (or beautifiers, yuck) , as do other tools. Let's put the rules into the machine and move on.
What should the rules be? Well, everybody has an opinion, but here are my definitive PL/SQL Coding Standards, with an addendum of formatting guidance.
APC's Damn Fine PL/SQL Coding Standards
- Your code must implement the requirements correctly and completely.
- Your code must have a suite of unit and integration tests (preferably automated) to prove it implements the requirements correctly and completely.
- Your code must implement the requirements as efficiently and performantly as possible.
APC's PL/SQL Code Formatting Guidelines
- Case. ALL CAPS is Teh Suck! Anything else is fine.
- Indentation. Align consistently. Spaces not tabs. Four spaces is the Goldilocks indent.
- Short statements. One statement per line.
- Long statements Use line breaks, don't make me scroll.
- Naming conventions. Use prefixes to distinguish local variables, global variables and parameters from each other and from database objects.
- Comments. A comment is an apology.