... |
... |
@@ -3,27 +3,7 @@ |
3 |
3 |
* **Functions should be small.** Maximum 20 lines. Blocks and indentation should also be short. Blocks inside if, else, or while statements should be one line. A function call should probably be included. Indentation depths should be no more than one or two levels. |
4 |
4 |
* **Functions should do only one task.** They should do its task well. They should do only that task. All instructions within the function should be on the same abstraction level. Sub-functions perform tasks which are one abstraction-level deeper. Sections within a function are symptoms that it performs more than one task. These function should be decomposed. |
5 |
5 |
* **One abstraction level per function.** The 'stepdown rule' states that code should be easy to read from top to bottom: Under a function, its subfunctions should go down one level of abstraction. |
6 |
|
-* The flow of reading should follow the flow of control. Here is an example: |
7 |
|
- |
8 |
|
-``` |
9 |
|
-func_1() { |
10 |
|
- func_2() |
11 |
|
- func_3() |
12 |
|
-} |
13 |
|
- |
14 |
|
-func_2() { |
15 |
|
- func_4 |
16 |
|
-} |
17 |
|
- |
18 |
|
-func_4() { |
19 |
|
- ... |
20 |
|
-} |
21 |
|
- |
22 |
|
-func_3(){ |
23 |
|
- ... |
24 |
|
-} |
25 |
|
-``` |
26 |
|
- |
|
6 |
+* **The flow of reading should follow the flow of control.** The flow of control is the chronological order in which a function is called. [[Here|doc:.Function Ordering Example.WebHome]] is an example. |
27 |
27 |
* **Separate statement and query.** Functions should either provide information about an object or do something with an object, but not both. |
28 |
28 |
* **Exceptions are better than error codes** (with if/else statements). |
29 |
29 |
* Error.java is a dependency magnet with its enumeration of error codes and should be replaced by exceptions and derivatives of the Exception class, which allows easy extensibility in accordance with the Open-Closed Principle. |