8000 Function names should say what they do · niklas-r/clean-code-javascript@e7ca5c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7ca5c9

Browse files
committed
Function names should say what they do
1 parent f83f4e4 commit e7ca5c9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,31 @@ function isClientActive(client) {
260260
```
261261
**[⬆ back to top](#table-of-contents)**
262262

263+
### Function names should say what they do
264+
265+
**Bad:**
266+
```javascript
267+
function dateAdd(date, month) {
268+
// ...
269+
}
270+
271+
let date = new Date();
272+
273+
// It's hard to to tell from the function name what is added
274+
dateAdd(date, 1);
275+
```
276+
277+
**Good**:
278+
```javascript
279+
function dateAddMonth(date, month) {
280+
// ...
281+
}
282+
283+
let date = new Date();
284+
dateAddMonth(date, 1);
285+
```
286+
**[⬆ back to top](#table-of-contents)**
287+
263288
### Remove duplicate code
264289
Never ever, ever, under any circumstance, have duplicate code. There's no reason
265290
for it and it's quite possibly the worst sin you can commit as a professional

0 commit comments

Comments
 (0)
0