Code Style: General Principles
I have always wanted to put together my personal code style guide. Now that I have a blog, I can do so rather easily.
This will be the first among many that details my approach to coding style. Yes, it is very particular to me. No, I don't expect anyone in their right mind to follow it. Though perhaps someone can use it as a general guideline.
I am fairly fanatical about style.
Parenthesis go on separate lines, always (I'll eventually contradict myself I'm sure). None of this my line starts with a comma crap. My only concession is that it makes commenting out lines easier. Otherwise, I can't stand it. It's ugly to me and I don't like ugly.
Tabs = 2 spaces
CREATE OR REPLACE is the top line followed by the particular object on the second line (I don't know why, it's my style though).
CREATE OR REPLACE
PACKAGE p_package
IS
...
Always put "show errors" at the bottom of procedure/function/package scripts.
Always end your procedure or function with the name after END.
CREATE OR REPLACE
PACKAGE p_package
IS
...
END p_package;
/
show errors
Align SELECT statements left, not right:
Evil
SELECT blah, t.id, s.x
FROM t, s
WHERE t.id = s.id
AND t.x = s.x;
Correct
SELECT
blah,
t.id,
s.x
FROM
t,
s
WHERE t.id = s.id
AND t.x = s.x;
I believe but can't confirm that Toad Formatter is the main perpetrator of this travesty.
Instrumentation. Use lots of it. Home grown or
Mr. Kyte's debug routine. You can also use the Oracle supplied package DBMS_APPLICATION_INFO. I have gotten into the habit of using set_session_longops and it helps tremendously in monitoring those pesky long running datawarehouse programs.
Be liberal in your use of spaces: ADD_MONTHS( TRUNC( SYSDATE, 'MONTH' ), 2 )
Capitalize keywords like SELECT, INSERT, UPDATE and DELETE.
Standard functions should also be capitalized.
I'm sure I've got more and I'll add them here as time goes on.
Labels: development, discipline, style