File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ getUser();
6868
**[⬆ back to top](#table-of-contents)**
6969

7070
### Use searchable names
71-
We will read more code than we will ever write. It's important that the code we do write is readable and searchable. By *not* naming variables that end up being meaningful for understanding our program, we hurt our readers. Make your names searchable.
71+
We will read more code than we will ever write. It's important that the code we
72+
do write is readable and searchable. By *not* naming variables that end up
73+
being meaningful for understanding our program, we hurt our readers.
74+
Make your names searchable.
7275

7376
**Bad:**
7477
```javascript
@@ -88,6 +91,23 @@ for (var i = 0; i < MINUTES_IN_A_YEAR; i++) {
8891
```
8992
**[⬆ back to top](#table-of-contents)**
9093

94+
### Use explanatory variables
95+
**Bad:**
96+
```javascript
97+
let cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/;
98+
saveCityState(cityStateRegex.match(cityStateRegex)[0], cityStateRegex.match(cityStateRegex)[0]);
99+
```
100+
101+
**Good**:
102+
```javascript
103+
let cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/;
104+
let match = cityStateRegex.match(cityStateRegex)
105+
let city = match[1];
106+
let state = match[2];
107+
saveCityState(city, state);
108+
```
109+
**[⬆ back to top](#table-of-contents)**
110+
91111
### Avoid Mental Mapping
92112
Explicit is better than implicit.
93113

0 commit comments

Comments
 (0)