Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix number order in the 2.2 section. #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions project_and_code_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class MyClass {
}
```

### 2.2.3 Treat acronyms as words
### 2.2.2 Treat acronyms as words

| Good | Bad |
| -------------- | -------------- |
Expand All @@ -162,7 +162,7 @@ public class MyClass {
| `String url` | `String URL` |
| `long id` | `long ID` |

### 2.2.4 Use spaces for indentation
### 2.2.3 Use spaces for indentation

Use __4 space__ indents for blocks:

Expand All @@ -179,7 +179,7 @@ Instrument i =
someLongExpression(that, wouldNotFit, on, one, line);
```

### 2.2.5 Use standard brace style
### 2.2.4 Use standard brace style

Braces go on the same line as the code before them.

Expand Down Expand Up @@ -212,9 +212,9 @@ if (condition)
body(); // bad!
```

### 2.2.6 Annotations
### 2.2.5 Annotations

#### 2.2.6.1 Annotations practices
#### 2.2.5.1 Annotations practices

According to the Android code style guide, the standard practices for some of the predefined annotations in Java are:

Expand All @@ -224,7 +224,7 @@ According to the Android code style guide, the standard practices for some of th

More information about annotation guidelines can be found [here](http://source.android.com/source/code-style.html#use-standard-java-annotations).

#### 2.2.6.2 Annotations style
#### 2.2.5.2 Annotations style

__Classes, Methods and Constructors__

Expand All @@ -245,13 +245,13 @@ Annotations applying to fields should be listed __on the same line__, unless the
@Nullable @Mock DataManager mDataManager;
```

### 2.2.7 Limit variable scope
### 2.2.6 Limit variable scope

_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._

_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](https://source.android.com/source/code-style.html#limit-variable-scope))

### 2.2.8 Order import statements
### 2.2.7 Order import statements

If you are using an IDE such as Android Studio, you don't have to worry about this because your IDE is already obeying these rules. If not, have a look below.

Expand All @@ -269,7 +269,7 @@ To exactly match the IDE settings, the imports should be:

More info [here](https://source.android.com/source/code-style.html#limit-variable-scope)

### 2.2.9 Logging guidelines
### 2.2.8 Logging guidelines

Use the logging methods provided by the `Log` class to print out error messages or other information that may be useful for developers to identify issues:

Expand Down Expand Up @@ -299,7 +299,7 @@ To only show logs on debug builds:
if (BuildConfig.DEBUG) Log.d(TAG, "The value of x is " + x);
```

### 2.2.10 Class member ordering
### 2.2.9 Class member ordering

There is no single correct solution for this but using a __logical__ and __consistent__ order will improve code learnability and readability. It is recommendable to use the following order:

Expand Down Expand Up @@ -360,7 +360,7 @@ public class MainActivity extends Activity {
}
```

### 2.2.11 Parameter ordering in methods
### 2.2.10 Parameter ordering in methods

When programming for Android, it is quite common to define methods that take a `Context`. If you are writing a method like this, then the __Context__ must be the __first__ parameter.

Expand All @@ -376,7 +376,7 @@ public User loadUser(Context context, int userId);
public void loadUserAsync(Context context, int userId, UserCallback callback);
```

### 2.2.13 String constants, naming, and values
### 2.2.11 String constants, naming, and values

Many elements of the Android SDK such as `SharedPreferences`, `Bundle`, or `Intent` use a key-value pair approach so it's very likely that even for a small app you end up having to write a lot of String constants.

Expand Down Expand Up @@ -405,7 +405,7 @@ static final String EXTRA_SURNAME = "com.myapp.extras.EXTRA_SURNAME";
static final String ACTION_OPEN_USER = "com.myapp.action.ACTION_OPEN_USER";
```

### 2.2.14 Arguments in Fragments and Activities
### 2.2.12 Arguments in Fragments and Activities

When data is passed into an `Activity `or `Fragment` via an `Intent` or a `Bundle`, the keys for the different values __must__ follow the rules described in the section above.

Expand Down Expand Up @@ -437,7 +437,7 @@ __Note 1__: These methods should go at the top of the class before `onCreate()`.

__Note 2__: If we provide the methods described above, the keys for extras and arguments should be `private` because there is not need for them to be exposed outside the class.

### 2.2.15 Line length limit
### 2.2.13 Line length limit

Code lines should not exceed __100 characters__. If the line is longer than this limit there are usually two options to reduce its length:

Expand All @@ -449,7 +449,7 @@ There are two __exceptions__ where it is possible to have lines longer than 100:
* Lines that are not possible to split, e.g. long URLs in comments.
* `package` and `import` statements.

#### 2.2.15.1 Line-wrapping strategies
#### 2.2.14.1 Line-wrapping strategies

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be 2.2.13.1


There isn't an exact formula that explains how to line-wrap and quite often different solutions are valid. However there are a few rules that can be applied to common cases.

Expand Down Expand Up @@ -501,7 +501,7 @@ loadPicture(context,
"Title of the picture");
```

### 2.2.16 RxJava chains styling
### 2.2.15 RxJava chains styling

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this should be 2.2.14


Rx chains of operators require line-wrapping. Every operator must go in a new line and the line should be broken before the `.`

Expand Down