forked from extern/naming-cheatsheet
Drop plural from count variable
Using e.g `fruitCount` instead of `fruitsCount` because it sounds more natural
This commit is contained in:
parent
c29a54e904
commit
aa3ee7defe
20
README.md
20
README.md
@ -51,11 +51,11 @@ const pages_count = 5
|
|||||||
const shouldUpdate = true
|
const shouldUpdate = true
|
||||||
|
|
||||||
/* Good */
|
/* Good */
|
||||||
const pagesCount = 5
|
const pageCount = 5
|
||||||
const shouldUpdate = true
|
const shouldUpdate = true
|
||||||
|
|
||||||
/* Good as well */
|
/* Good as well */
|
||||||
const pages_count = 5
|
const page_count = 5
|
||||||
const should_update = true
|
const should_update = true
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -70,13 +70,13 @@ A name must be _short_, _intuitive_ and _descriptive_:
|
|||||||
```js
|
```js
|
||||||
/* Bad */
|
/* Bad */
|
||||||
const a = 5 // "a" could mean anything
|
const a = 5 // "a" could mean anything
|
||||||
const isPaginatable = postsCount > 10 // "Paginatable" sounds extremely unnatural
|
const isPaginatable = a > 10 // "Paginatable" sounds extremely unnatural
|
||||||
const shouldPaginatize = postsCount > 10 // Made up verbs are so much fun!
|
const shouldPaginatize = a > 10 // Made up verbs are so much fun!
|
||||||
|
|
||||||
/* Good */
|
/* Good */
|
||||||
const postsCount = 5
|
const postCount = 5
|
||||||
const hasPagination = postsCount > 10
|
const hasPagination = postCount > 10
|
||||||
const shouldDisplayPagination = postsCount > 10 // alternatively
|
const shouldDisplayPagination = postCount > 10 // alternatively
|
||||||
```
|
```
|
||||||
|
|
||||||
## Avoid contractions
|
## Avoid contractions
|
||||||
@ -111,11 +111,11 @@ A name should reflect the expected result.
|
|||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
/* Bad */
|
/* Bad */
|
||||||
const isEnabled = itemsCount > 3
|
const isEnabled = itemCount > 3
|
||||||
return <Button disabled={!isEnabled} />
|
return <Button disabled={!isEnabled} />
|
||||||
|
|
||||||
/* Good */
|
/* Good */
|
||||||
const isDisabled = itemsCount <= 3
|
const isDisabled = itemCount <= 3
|
||||||
return <Button disabled={isDisabled} />
|
return <Button disabled={isDisabled} />
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ The verb part of your function name. The most important part responsible for des
|
|||||||
Accesses data immediately (i.e. shorthand getter of internal data).
|
Accesses data immediately (i.e. shorthand getter of internal data).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function getFruitsCount() {
|
function getFruitCount() {
|
||||||
return this.fruits.length
|
return this.fruits.length
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user