Skip to content
Merged
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
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,19 +716,77 @@ top-to-bottom, like a newspaper. Because of this, make your code read that way.
Comments are an apology, not a requirement. Good code *mostly* documents itself.

**Bad:**
```java
// Creating a List of customer names
List<String> customerNames = Arrays.asList('Bob', 'Linda', 'Steve', 'Mary');

// Using Stream findFirst()
Optional<String> firstCustomer = customerNames.stream().findFirst();

// if the stream is empty, an empty
// Optional is returned.
if (firstCustomer.isPresent()) {
System.out.println(firstCustomer.get());
}
else {
System.out.println("no value");
}
```


**Good:**
```java
List<String> customerNames = Arrays.asList('Bob', 'Linda', 'Steve', 'Mary');

Optional<String> firstCustomer = customerNames.stream().findFirst();

if (firstCustomer.isPresent()) {
System.out.println(firstCustomer.get());
}
else {
System.out.println("no value");
}
```

**[⬆ back to top](#table-of-contents)**

### Don't Use a Comment When You Can Use a Function or a Variable
The best comment is no comment

**Bad:**
```java
//Check to see if order is eligible to ship
if((order.isPaid & order.isLabeled) && CUSTOMER_FLAG) {
// ...
}
```


**Good:**
```java
if(order.isEligibleToShip()) {
// ...
}
```

**[⬆ back to top](#table-of-contents)**

### Don't leave commented out code in your codebase
Version control exists for a reason. Leave old code in your history.

**Bad:**
```java
doStuff();
// doOtherStuff();
// doSomeMoreStuff();
// doSoMuchStuff();
```


**Good:**
```java
doStuff();
```

**[⬆ back to top](#table-of-contents)**

Expand All @@ -737,8 +795,23 @@ Remember, use version control! There's no need for dead code, commented code,
and especially journal comments. Use `git log` to get history!

**Bad:**
```java
/**
* 2021-03-06: Renamed clean to cleanCode (DL)
* 2020-01-03: Changed return value (LB)
* 2019-05-12: Added clean method (DL)
*/
cleanCode(String code) {
return null;
}
```

**Good:**
```java
cleanCode(String code) {
return null;
}
```

**[⬆ back to top](#table-of-contents)**

Expand All @@ -747,8 +820,25 @@ They usually just add noise. Let the functions and variable names along with the
proper indentation and formatting give the visual structure to your code.

**Bad:**
```java
////////////////////////////////////////////////////////////////////////////////
// Instantiate Order List
////////////////////////////////////////////////////////////////////////////////
List<Order> orders = new ArrayList();

////////////////////////////////////////////////////////////////////////////////
// Ship Orders that are eligible
////////////////////////////////////////////////////////////////////////////////

orders.filter(Order::isEligibleToShip).forEach(x -> ship(x));
```

**Good:**
```java
List<Order> orders = new ArrayList();

orders.filter(Order::isEligibleToShip).forEach(x -> ship(x));
```

**[⬆ back to top](#table-of-contents)**

Expand Down