You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: project_style_guidelines.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The aim of this document is to define project guidelines. These should be follow
8
8
9
9
###1.1 Project Structure
10
10
11
-
When commiting work, the project should maintain the following structure:
11
+
When contributing work, the project should maintain the following structure:
12
12
13
13
14
14
@@ -23,7 +23,7 @@ When commiting work, the project should maintain the following structure:
23
23
**CommonTest** - Directory containing shared test code for AndroidTest & Test
24
24
**main** - Directory containing application code
25
25
26
-
The structure of the project should remain as documentation whenever you are modifying or adding new features.
26
+
The structure of the project should remain as defined above whenever you are modifying or adding new features.
27
27
28
28
Using this structure allows us to keep the application code seperated from any test-related code. The CommonTest directory allows us to share classes between the functional and unit tests, such as mock model creation and dagger test configuration classes.
29
29
@@ -41,15 +41,15 @@ Any classes extending an Android framework component should **always** end with
We use UpperCamelCase as this helps to seperate the words used to create the name, making it easier to read. Naming classes to end with the framework component makes it super clear as to what the class is used for. For example, if you're looking to make changes to the RegistrationDialog then this naming convention makes it super easy to locate.
44
+
We use UpperCamelCase as this helps to seperate the words used to create the name, making it easier to read. Naming classes to end with the framework component makes it super clear as to what the class is used for. For example, if you're looking to make changes to the RegistrationDialog then this naming convention makes it really easy to locate that class.
45
45
46
46
####1.2.1 Resource Files
47
47
48
48
When naming resource files you should be sure to name them using lowercase letters and underscores instead of spaces, for example:
49
49
50
50
activity_main, fragment_user, item_post
51
51
52
-
This convention again makes it really easy to locate the layout for a specific file. Within android studio, the layout package is sorted in alphabetical order meaning that activity, fragment and other layout types becomes grouped - so you know where to begin looking for a layout file. Other than this, begining the file name with the component name makes it clear what component/class the layout file is being used for.
52
+
This convention again makes it really easy to locate the specific layout file that you're looking for. Within android studio, the layout package is sorted in alphabetical order meaning that activity, fragment and other layout types becomes grouped - so you know where to begin looking for a file. Other than this, begining the file name with the component name makes it clear what component/class the layout file is being used for.
53
53
54
54
55
55
####1.2.2.1 Drawable Files
@@ -107,7 +107,7 @@ Not only does this approach makes it easy to find files in the directory hierarc
107
107
108
108
####1.2.2.3 Menu Files
109
109
110
-
Menu files do not need to be prefixed with the menu_ prefix. This is because they are already in the menu package in the res directory, so it is not a requirement.
110
+
Menu files do not need to be prefixed with the menu_ prefix. This is because they are already in the menu package in the resources directory, so it is not a requirement.
111
111
112
112
####1.2.2.4 Values Files
113
113
@@ -136,9 +136,9 @@ This gives no information to both the developer and the user, making it harder t
136
136
137
137
public void setCount(String count) {
138
138
try {
139
-
mCount = Integer.parseInt(id);
139
+
count = Integer.parseInt(id);
140
140
} catch (NumberFormatException e) {
141
-
mCount = 0;
141
+
count = 0;
142
142
Log.e(TAG, "There was an error parsing the count " + e);
@@ -168,7 +168,7 @@ Catching exceptions generally should not be done:
168
168
169
169
Why?
170
170
171
-
*Do not do this. In almost all cases it is inappropriate to catch generic Exception or Throwable (preferably not Throwable because it includes Error exceptions). It is very dangerous because it means that Exceptions you never expected (including RuntimeExceptions like ClassCastException) get caught in application-level error handling. It obscures the failure handling properties of your code, meaning if someone adds a new type of Exception in the code you're calling, the compiler won't help you realize you need to handle the error differently. In most cases you shouldn't be handling different types of exception the same way.* - Android Code Style Guidelines
171
+
*Do not do this. In almost all cases it is inappropriate to catch generic Exception or Throwable (preferably not Throwable because it includes Error exceptions). It is very dangerous because it means that Exceptions you never expected (including RuntimeExceptions like ClassCastException) get caught in application-level error handling. It obscures the failure handling properties of your code, meaning if someone adds a new type of Exception in the code you're calling, the compiler won't help you realize you need to handle the error differently. In most cases you shouldn't be handling different types of exception the same way.* - taken from the Android Code Style Guidelines
172
172
173
173
Instead, catch the expected exception and handle it accordingly:
174
174
@@ -220,7 +220,7 @@ Using try-catch statements improves the readability of the code where the except
220
220
221
221
####2.1.5 Never use Finalizers
222
222
223
-
*There are no guarantees as to when a finalizer will be called, or even that it will be called at all. In most cases, you can do what you need from a finalizer with good exception handling. If you absolutely need it, define a close() method (or the like) and document exactly when that method needs to be called. See InputStreamfor an example. In this case it is appropriate but not required to print a short log message from the finalizer, as long as it is not expected to flood the logs.* - (Android code style guidelines)
223
+
*There are no guarantees as to when a finalizer will be called, or even that it will be called at all. In most cases, you can do what you need from a finalizer with good exception handling. If you absolutely need it, define a close() method (or the like) and document exactly when that method needs to be called. See InputStreamfor an example. In this case it is appropriate but not required to print a short log message from the finalizer, as long as it is not expected to flood the logs.* - taken from the Android code style guidelines
224
224
225
225
226
226
@@ -394,7 +394,7 @@ For blocks, 4 space indentation should be used:
394
394
395
395
396
396
if (userSignedIn) {
397
-
mCount = 1;
397
+
count = 1;
398
398
}
399
399
400
400
Whereas for line wraps, 8 spaces should be used:
@@ -551,7 +551,7 @@ We do this as it makes the statement easier to read, for example the statement '
551
551
552
552
The scope of local variables should be kept to a minimum (Effective Java Item 29). By doing so, you increase the readability and maintainability of your code and reduce the likelihood of error. Each variable should be declared in the innermost block that encloses all uses of the variable.
553
553
554
-
Local variables should be declared at the point they are first used. Nearly every local variable declaration should contain an initializer. If you don't yet have enough information to initialize a variable sensibly, you should postpone the declaration until you do. - (Android code style guidelines)
554
+
Local variables should be declared at the point they are first used. Nearly every local variable declaration should contain an initializer. If you don't yet have enough information to initialize a variable sensibly, you should postpone the declaration until you do. - taken from the Android code style guidelines
555
555
556
556
557
557
####2.2.12 Unused elements
@@ -560,7 +560,7 @@ All unused **fields**, **imports**, **methods** and **classes** should be remove
560
560
561
561
####2.2.13 Order Import Statements
562
562
563
-
We use Android Studio, so imports should always be ordered automatically. However, in the case that they aren’t, then the following applies:
563
+
Because we use Android Studio, so imports should always be ordered automatically. However, in the case that they may not be, then they should be ordered as follows:
564
564
565
565
566
566
1. Android imports
@@ -570,8 +570,8 @@ We use Android Studio, so imports should always be ordered automatically. Howeve
570
570
571
571
**Note:**
572
572
573
-
- Imports should be alphabetically ordered within each grouping, with capital letters before lower case letters (e.g. Z before a).
574
-
- There should be a blank line between each major grouping (android, com, junit, net, org, java, javax).
573
+
- Imports should be alphabetically ordered within each grouping, with capital letters before lower case letters (e.g. Z before a)
574
+
- There should be a blank line between each major grouping (android, com, junit, net, org, java, javax)
0 commit comments