Coding Style
Formatting
Rules
Rule | Description |
---|---|
1 | Keywords and names are written in lowercase1. |
2 | 3 space indention2. |
3 | One command per line. |
4 | Keywords loop , else , elsif , end if , when on a new line. |
5 | Commas in front of separated elements. |
6 | Call parameters aligned, operators aligned, values aligned. |
7 | SQL keywords are right aligned within a SQL command. |
8 | Within a program unit only line comments -- are used. |
9 | Brackets are used when needed or when helpful to clarify a construct. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Code Commenting
Conventions
Inside a program unit only use the line commenting technique --
unless you temporarly deactivate code sections for testing.
To comment the source code for later document generation, comments like /** ... */
are used. Within these documentation comments, tags may be used to define the documentation structure.
Tools like Oracle SQL Developer or PL/SQL Developer include documentation functionality based on a javadoc-like tagging.
Commenting Tags
Tag | Meaning | Example |
---|---|---|
param |
Description of a parameter. | @param in_string input string |
return |
Description of the return value of a function. | @return result of the calculation |
throws |
Describe errors that may be raised by the program unit. | @throws NO_DATA_FOUND |
Example
This is an example using the documentation capabilities of SQL Developer.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
-
It used to be good practice to use uppercase keywords and lowercase names to help visualize code structure. But practically all editors support more or less advanced color highlighting of code, similar to the examples in these guidelines. Hence as of version 4.0 we are now recommending all lowercase, as this is easier and faster for the brain to process. You may choose to prefer the old rule - however, it is important to always be consistent, like for example keywords always in uppercase and names always in lowercase. ↩
-
Tabs are not used because the indentation depends on the editor configuration. We want to ensure that the code looks the same, independent of the editor used. Hence, no tabs. But why not use 8 spaces? That's the traditional value for a tab. When writing a package function the code in the body has an indentation of 3. That's 24 characters as a starting point for the code. We think it's too much. Especially if we try to keep a line below 100 or 80 characters. Other good options would be 2 or 4 spaces. We settled for 3 spaces as a compromise. The indentation is still good visible, but does not use too much space. ↩