Skip to content

Commit

Permalink
Docs: Document accessing instance variables (#11087)
Browse files Browse the repository at this point in the history
  • Loading branch information
aokolnychyi authored Sep 7, 2024
1 parent 6e05ae0 commit ab2c6f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions site/docs/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,34 @@ When passing boolean arguments to existing or external methods, use inline comme
dropTable(identifier, purge);
```

#### Accessing instance variables

Use `this` when assigning values to instance variables, making it clear when the object's state is being changed. Omit `this` when reading instance variables to keep lines shorter.

```java
private String value;

// BAD: unnecessary `this` during reads
public String value() {
return this.value;
}

// GOOD: no `this` when reading instance variables
public String value() {
return value;
}

// BAD: missing `this` in assignments
public void value(String newValue) {
value = newValue;
}

// GOOD: use `this` in assignments
public void value(String newValue) {
this.value = newValue;
}
```

#### Config naming

1. Use `-` to link words in one concept
Expand Down

0 comments on commit ab2c6f8

Please sign in to comment.