Skip to content

Commit 28b46cb

Browse files
authored
Merge pull request #86 from kibeha/main
Changes for version 4.0
2 parents 2756153 + e2c82be commit 28b46cb

File tree

115 files changed

+2941
-2310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2941
-2310
lines changed

docs/1-introduction/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ There are basically two types of standards.
7878

7979
2. Controversial
8080

81-
Almost every rule/guildeline falls into this category. An example of this category is [3 space indention](../../3-coding-style/coding-style/#rules). - Why not 2 or 4 or even 8? Why not use tabs? You can argue in favor of all these options. In most cases it does not really matter which option you choose. Being consistent is more important. In this case it will make the code easier to read.
81+
Almost every rule/guideline falls into this category. An example of this category is [3 space indention](../../3-coding-style/coding-style/#rules). - Why not 2 or 4 or even 8? Why not use tabs? You can argue in favor of all these options. In most cases it does not really matter which option you choose. Being consistent is more important. In this case it will make the code easier to read.
8282

8383
For very controversial rules, we have started to include the reasoning either as a footnote or directly in the text.
8484

docs/2-naming-conventions/naming-conventions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
4. Avoid long abbreviations. Abbreviations should be shorter than 5 characters.
99
5. Any abbreviations must be widely known and accepted.
1010
6. Create a glossary with all accepted abbreviations.
11-
7. Never use ORACLE keywords as names. A list of ORACLEs keywords may be found in the dictionary view `V$RESERVED_WORDS`.
12-
8. Avoid adding redundant or meaningless prefixes and suffixes to identifiers.<br/>Example: `CREATE TABLE emp_table`.
11+
7. Never use ORACLE keywords as names. A list of ORACLEs keywords may be found in the dictionary view `v$reserved_words`.
12+
8. Avoid adding redundant or meaningless prefixes and suffixes to identifiers.<br/>Example: `create table emp_table`.
1313
9. Always use one spoken language (e.g. English, German, French) for all objects in your application.
1414
10. Always use the same names for elements with the same meaning.
1515

docs/3-coding-style/coding-style.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
Rule | Description
88
:--: | -----------
9-
1 | Keywords are written uppercase, names are written in lowercase.
10-
2 | 3 space indention[^2].
9+
1 | Keywords and names are written in lowercase[^2].
10+
2 | 3 space indention[^3].
1111
3 | One command per line.
12-
4 | Keywords `LOOP`, `ELSE`, `ELSIF`, `END IF`, `WHEN` on a new line.
12+
4 | Keywords `loop`, `else`, `elsif`, `end if`, `when` on a new line.
1313
5 | Commas in front of separated elements.
1414
6 | Call parameters aligned, operators aligned, values aligned.
1515
7 | SQL keywords are right aligned within a SQL command.
@@ -18,34 +18,34 @@ Rule | Description
1818

1919
### Example
2020

21-
```
22-
PROCEDURE set_salary(in_employee_id IN employees.employee_id%TYPE) IS
23-
CURSOR c_employees(p_employee_id IN employees.employee_id%TYPE) IS
24-
SELECT last_name
21+
``` sql
22+
procedure set_salary(in_employee_id in employees.employee_id%type) is
23+
cursor c_employees(p_employee_id in employees.employee_id%type) is
24+
select last_name
2525
,first_name
2626
,salary
27-
FROM employees
28-
WHERE employee_id = p_employee_id
29-
ORDER BY last_name
27+
from employees
28+
where employee_id = p_employee_id
29+
order by last_name
3030
,first_name;
3131

32-
r_employee c_employees%ROWTYPE;
33-
l_new_salary employees.salary%TYPE;
34-
BEGIN
35-
OPEN c_employees(p_employee_id => in_employee_id);
36-
FETCH c_employees INTO r_employee;
37-
CLOSE c_employees;
32+
r_employee c_employees%rowtype;
33+
l_new_salary employees.salary%type;
34+
begin
35+
open c_employees(p_employee_id => in_employee_id);
36+
fetch c_employees into r_employee;
37+
close c_employees;
3838

3939
new_salary (in_employee_id => in_employee_id
4040
,out_salary => l_new_salary);
4141

4242
-- Check whether salary has changed
43-
IF r_employee.salary <> l_new_salary THEN
44-
UPDATE employees
45-
SET salary = l_new_salary
46-
WHERE employee_id = in_employee_id;
47-
END IF;
48-
END set_salary;
43+
if r_employee.salary <> l_new_salary then
44+
update employees
45+
set salary = l_new_salary
46+
where employee_id = in_employee_id;
47+
end if;
48+
end set_salary;
4949
```
5050

5151
## Code Commenting
@@ -70,7 +70,7 @@ Tag | Meaning | Example
7070

7171
This is an example using the documentation capabilities of SQL Developer.
7272

73-
```
73+
``` sql
7474
/**
7575
Check whether we passed a valid sql name
7676
@@ -80,15 +80,21 @@ Check whether we passed a valid sql name
8080
8181
<b>Call Example:</b>
8282
<pre>
83-
SELECT TVDAssert.valid_sql_name('TEST') from dual;
84-
SELECT TVDAssert.valid_sql_name('123') from dual
83+
select TVDAssert.valid_sql_name('TEST') from dual;
84+
select TVDAssert.valid_sql_name('123') from dual
8585
</pre>
8686
*/
8787
```
8888

8989
[^2]:
90+
It used to be good practice to use uppercase keywords and lowercase names to help visualize code structure.
91+
But practically all editors support more or less advanced color highlighting of code, similar to the examples in these guidelines.
92+
Hence as of version 4.0 we are now recommending all lowercase, as this is easier and faster for the brain to process.
93+
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.
94+
95+
[^3]:
9096
Tabs are not used because the indentation depends on the editor configuration.
91-
We want to ensure that the code looks the same, indepenent of the editor used.
97+
We want to ensure that the code looks the same, independent of the editor used.
9298
Hence, no tabs. But why not use 8 spaces? That's the traditional value for a tab.
9399
When writing a package function the code in the body has an indentation of 3.
94100
That's 24 characters as a starting point for the code. We think it's too much.

docs/4-language-usage/1-general/g-1010.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@ It's a good alternative for comments to indicate the start and end of a named pr
99

1010
## Example (bad)
1111

12-
```
13-
BEGIN
14-
BEGIN
15-
NULL;
16-
END;
17-
18-
BEGIN
19-
NULL;
20-
END;
21-
END;
12+
``` sql
13+
begin
14+
begin
15+
null;
16+
end;
17+
18+
begin
19+
null;
20+
end;
21+
end;
2222
/
2323
```
2424

2525
## Example (good)
2626

27-
```
28-
BEGIN
27+
``` sql
28+
begin
2929
<<prepare_data>>
30-
BEGIN
31-
NULL;
32-
END prepare_data;
30+
begin
31+
null;
32+
end prepare_data;
3333

3434
<<process_data>>
35-
BEGIN
36-
NULL;
37-
END process_data;
38-
END good;
35+
begin
36+
null;
37+
end process_data;
38+
end good;
3939
/
4040
```

docs/4-language-usage/1-general/g-1020.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,84 +8,84 @@
88
Use a label directly in front of loops and nested anonymous blocks:
99

1010
* To give a name to that portion of code and thereby self-document what it is doing.
11-
* So that you can repeat that name with the END statement of that block or loop.
11+
* So that you can repeat that name with the `end` statement of that block or loop.
1212

1313
## Example (bad)
1414

15-
```
16-
DECLARE
17-
i INTEGER;
18-
co_min_value CONSTANT INTEGER := 1;
19-
co_max_value CONSTANT INTEGER := 10;
20-
co_increment CONSTANT INTEGER := 1;
21-
BEGIN
15+
``` sql
16+
declare
17+
i integer;
18+
co_min_value constant integer := 1;
19+
co_max_value constant integer := 10;
20+
co_increment constant integer := 1;
21+
begin
2222
<<prepare_data>>
23-
BEGIN
24-
NULL;
25-
END;
23+
begin
24+
null;
25+
end;
2626

2727
<<process_data>>
28-
BEGIN
29-
NULL;
30-
END;
28+
begin
29+
null;
30+
end;
3131

3232
i := co_min_value;
3333
<<while_loop>>
34-
WHILE (i <= co_max_value)
35-
LOOP
34+
while (i <= co_max_value)
35+
loop
3636
i := i + co_increment;
37-
END LOOP;
37+
end loop;
3838

3939
<<basic_loop>>
40-
LOOP
41-
EXIT basic_loop;
42-
END LOOP;
40+
loop
41+
exit basic_loop;
42+
end loop;
4343

4444
<<for_loop>>
45-
FOR i IN co_min_value..co_max_value
46-
LOOP
45+
for i in co_min_value..co_max_value
46+
loop
4747
sys.dbms_output.put_line(i);
48-
END LOOP;
49-
END;
48+
end loop;
49+
end;
5050
/
5151
```
5252

5353
## Example (good)
5454

55-
```
56-
DECLARE
57-
i INTEGER;
58-
co_min_value CONSTANT INTEGER := 1;
59-
co_max_value CONSTANT INTEGER := 10;
60-
co_increment CONSTANT INTEGER := 1;
61-
BEGIN
55+
``` sql
56+
declare
57+
i integer;
58+
co_min_value constant integer := 1;
59+
co_max_value constant integer := 10;
60+
co_increment constant integer := 1;
61+
begin
6262
<<prepare_data>>
63-
BEGIN
64-
NULL;
65-
END prepare_data;
63+
begin
64+
null;
65+
end prepare_data;
6666

6767
<<process_data>>
68-
BEGIN
69-
NULL;
70-
END process_data;
68+
begin
69+
null;
70+
end process_data;
7171

7272
i := co_min_value;
7373
<<while_loop>>
74-
WHILE (i <= co_max_value)
75-
LOOP
74+
while (i <= co_max_value)
75+
loop
7676
i := i + co_increment;
77-
END LOOP while_loop;
77+
end loop while_loop;
7878

7979
<<basic_loop>>
80-
LOOP
81-
EXIT basic_loop;
82-
END LOOP basic_loop;
80+
loop
81+
exit basic_loop;
82+
end loop basic_loop;
8383

8484
<<for_loop>>
85-
FOR i IN co_min_value..co_max_value
86-
LOOP
85+
for i in co_min_value..co_max_value
86+
loop
8787
sys.dbms_output.put_line(i);
88-
END LOOP for_loop;
89-
END;
88+
end loop for_loop;
89+
end;
9090
/
9191
```

docs/4-language-usage/1-general/g-1030.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,45 @@ Unused variables decrease the maintainability and readability of your code.
99

1010
## Example (bad)
1111

12-
```
13-
CREATE OR REPLACE PACKAGE BODY my_package IS
14-
PROCEDURE my_proc IS
15-
l_last_name employees.last_name%TYPE;
16-
l_first_name employees.first_name%TYPE;
17-
co_department_id CONSTANT departments.department_id%TYPE := 10;
18-
e_good EXCEPTION;
19-
BEGIN
20-
SELECT e.last_name
21-
INTO l_last_name
22-
FROM employees e
23-
WHERE e.department_id = co_department_id;
24-
EXCEPTION
25-
WHEN no_data_found THEN NULL; -- handle_no_data_found;
26-
WHEN too_many_rows THEN null; -- handle_too_many_rows;
27-
END my_proc;
28-
END my_package;
12+
``` sql
13+
create or replace package body my_package is
14+
procedure my_proc is
15+
l_last_name employees.last_name%type;
16+
l_first_name employees.first_name%type;
17+
co_department_id constant departments.department_id%type := 10;
18+
e_good exception;
19+
begin
20+
select e.last_name
21+
into l_last_name
22+
from employees e
23+
where e.department_id = co_department_id;
24+
exception
25+
when no_data_found then null; -- handle_no_data_found;
26+
when too_many_rows then null; -- handle_too_many_rows;
27+
end my_proc;
28+
end my_package;
2929
/
3030
```
3131

3232
## Example (good)
3333

34-
```
35-
CREATE OR REPLACE PACKAGE BODY my_package IS
36-
PROCEDURE my_proc IS
37-
l_last_name employees.last_name%TYPE;
38-
co_department_id CONSTANT departments.department_id%TYPE := 10;
39-
e_good EXCEPTION;
40-
BEGIN
41-
SELECT e.last_name
42-
INTO l_last_name
43-
FROM employees e
44-
WHERE e.department_id = co_department_id;
45-
46-
RAISE e_good;
47-
EXCEPTION
48-
WHEN no_data_found THEN NULL; -- handle_no_data_found;
49-
WHEN too_many_rows THEN null; -- handle_too_many_rows;
50-
END my_proc;
51-
END my_package;
34+
``` sql
35+
create or replace package body my_package is
36+
procedure my_proc is
37+
l_last_name employees.last_name%type;
38+
co_department_id constant departments.department_id%type := 10;
39+
e_good exception;
40+
begin
41+
select e.last_name
42+
into l_last_name
43+
from employees e
44+
where e.department_id = co_department_id;
45+
46+
raise e_good;
47+
exception
48+
when no_data_found then null; -- handle_no_data_found;
49+
when too_many_rows then null; -- handle_too_many_rows;
50+
end my_proc;
51+
end my_package;
5252
/
5353
```

0 commit comments

Comments
 (0)