Skip to content

Commit ca35d65

Browse files
committed
Fix #57 - Altered rule to all lowercase. Added footnote on reason and importance of consistency. Converted all code examples to lowercase (thanks Philipp for https://www.salvis.com/blog/2020/08/28/formatting-sql-code-blocks-in-markdown-files/ )
1 parent 81c2836 commit ca35d65

File tree

90 files changed

+1946
-1940
lines changed

Some content is hidden

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

90 files changed

+1946
-1940
lines changed

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
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.
1212
4 | Keywords `LOOP`, `ELSE`, `ELSIF`, `END IF`, `WHEN` on a new line.
1313
5 | Commas in front of separated elements.
@@ -19,33 +19,33 @@ Rule | Description
1919
### Example
2020

2121
``` 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
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
@@ -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: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ It's a good alternative for comments to indicate the start and end of a named pr
1010
## Example (bad)
1111

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

2525
## Example (good)
2626

2727
``` sql
28-
BEGIN
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: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,79 +13,79 @@ Use a label directly in front of loops and nested anonymous blocks:
1313
## Example (bad)
1414

1515
``` 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
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

5555
``` 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
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: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,44 @@ Unused variables decrease the maintainability and readability of your code.
1010
## Example (bad)
1111

1212
``` 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;
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

3434
``` 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;
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)